forked from Berzeg07/learn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.html
60 lines (52 loc) · 1.27 KB
/
menu.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<title>Learn JS</title>
</head>
<body>
<script src="js/jquery-1.12.0.min.js"></script>
<div class="container">
<div id="nav">
<div class="menu-item">
Меню 1
<div class="submenu">Подменю 1</div>
</div>
<div class="menu-item">
Меню 1
<div class="submenu">Подменю 2</div>
</div>
<div class="menu-item">
Меню 1
<div class="submenu">Подменю 3</div>
</div>
</div>
<!-- script -->
<script>
document.getElementById('nav').onmouseover = function(event) {
var target = event.target;
if(target.className == 'menu-item') {
var s = target.getElementsByClassName('submenu');
closeMenu();
s[0].style.display='block';
}
}
document.onmouseover = function(event){
var target = event.target;
if(target.className!='menu-item' && target.className!='submenu'){
closeMenu();
}
}
function closeMenu() {
var menu = document.getElementById('nav');
var subm = document.getElementsByClassName('submenu');
for (var i = 0; i < subm.length; i++){
subm[i].style.display="none";
}
}
</script>
</div>
<!-- container -->
</body>
</html>