-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhover_demo.html
More file actions
61 lines (55 loc) · 1.51 KB
/
Copy pathhover_demo.html
File metadata and controls
61 lines (55 loc) · 1.51 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hover_demo</title>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<style>
header {
text-align: center;
}
.sub-menu {
position: absolute;
width: 200px;
height: 200px;
background-color: lime;
display: none;
}
</style>
</head>
<body>
<article>
<header>
<nav>
<a href="#">菜单1</a>
<a href="#">菜单2</a>
</nav>
</header>
</article>
<div class="sub-menu">
菜单展示
</div>
<script>
$('header a').hover(function () {
console.log('onmouseenter');
var offset = $(this).offset();
$('.sub-menu').show().css({
left: offset.left,
top: offset.top + $(this).height()
});
}, function () {
console.log('onmouseout');
$('.sub-menu').hide();
});
$('.sub-menu').hover(function (){
$(this).show();
}, function () {
$(this).hide();
})
// 二级菜单的展示可以做成接口的形式,棒棒哒
//
</script>
</body>
</html>