forked from iliakan/javascript-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.html
More file actions
76 lines (61 loc) · 1.22 KB
/
menu.html
File metadata and controls
76 lines (61 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
.menu ul {
margin: 0;
list-style: none;
padding-left: 20px;
display: none;
}
.menu .title {
font-size: 18px;
cursor: pointer;
}
.menu .title::before {
color: green;
font-size: 80%;
content: '▶ ';
}
.menu_open .title::before {
color: green;
font-size: 80%;
content: '▼ ';
}
.menu_open ul {
display: block;
}
</style>
</head>
<body>
<div id="sweeties" class="menu">
<span class="title">Сладости (нажми меня)!</span>
<ul>
<li>Торт</li>
<li>Пончик</li>
<li>Пирожное</li>
</ul>
</div>
<script>
function Menu(options) {
var elem = options.elem;
function toggle() {
elem.classList.toggle('menu_open');
}
elem.onclick = function(event) {
console.log(event);
console.log(this == elem);
toggle();
}
this.toggle = toggle;
}
var menu = new Menu({
elem: document.querySelector('#sweeties')
});
setInterval(function() {
menu.toggle();
}, 3000)
</script>
</body>
</html>