forked from WangJia-mm/JavaScript201708
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6-menu2.html
More file actions
79 lines (71 loc) · 1.76 KB
/
6-menu2.html
File metadata and controls
79 lines (71 loc) · 1.76 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
77
78
79
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>珠峰培训</title>
<link rel="stylesheet" href="css/reset.min.css">
<style>
html, body {
width: 100%;
height: 100%;
overflow: hidden;
}
.menu {
margin: 50px auto;
width: 200px;
}
.menu a {
display: block;
padding: 0 10px;
line-height: 35px;
border: 1px solid #999;
font-size: 16px;
color: lightcoral;
}
.menu .shop {
display: none;
border: 1px solid #999;
border-top: none;
}
.menu .shop li {
padding-left: 15px;
line-height: 30px;
}
/*--CSS3--*/
.menu .shop li:nth-child(even) {
background: lightgoldenrodyellow;
}
.menu .shop li:hover {
background: lightcyan;
}
</style>
</head>
<body>
<div class="menu">
<a href="javascript:;" class="menuLink">购物车</a>
<ul class="shop">
<li>玫瑰花</li>
<li>情侣表</li>
<li>电影票</li>
<li>LV包包</li>
</ul>
</div>
<script src="js/jquery-1.11.3.min.js"></script>
<script>
var $shop = $('.menu>.shop');
$('body').click(function (e) {
var target = e.target,
$target = $(target);
if (target.tagName.toUpperCase() === 'A' && $target.hasClass('menuLink')) {
$shop.stop().slideToggle(100);
return;
}
$shop.stop().slideUp(100);
});
$shop.children('li').click(function (e) {
//->阻止冒泡传播:不让其执行BODY上的那一套
e.stopPropagation();
});
</script>
</body>
</html>