en.javascript.info/02-ui/02-events-and-interfaces/01-introduction-browser-events/04-sliding-menu/solution/index.html
Ilya Kantor f301cb744d init
2014-10-26 22:10:13 +03:00

57 lines
932 B
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
.menu ul {
margin: 0;
list-style: none;
padding-left: 20px;
display: none;
}
.menu .title {
padding-left: 16px;
font-size: 18px;
cursor: pointer;
background: url(http://js.cx/clipart/arrow-right.png) left center no-repeat;
}
.menu-open .title {
background: url(http://js.cx/clipart/arrow-down.png) left center no-repeat;
}
.menu-open ul {
display: block;
}
</style>
</head>
<body>
<div id="sweeties" class="menu">
<span id="sweeties-title" class="title">Сладости (нажми меня)!</span>
<ul>
<li>Торт</li>
<li>Пончик</li>
<li>Пирожное</li>
</ul>
</div>
<script>
var titleElem = document.getElementById('sweeties-title');
titleElem.onclick = function() {
var menu = this.parentNode;
menu.classList.toggle('menu-open');
};
</script>
</body>
</html>