-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path12_例子2.html
83 lines (65 loc) · 1.21 KB
/
12_例子2.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
width:50px;
height: 50px;
float:left;
border-radius: 50%;
text-align: center;
line-height: 50px;
border: 1px solid #000;
cursor: pointer;
}
.active{
background: skyblue;
}
.red{
background: red;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<script src="jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
/*
$().each(function(i,e){//跟forEach参数对调
})
index(); //当前元素相对于兄弟元素的索引
移入
*/
$('li').mouseover(function(){
if($(this).index() < 2){
$('li').removeClass('active');
$('li').removeClass('red');
let num = $(this).index()+1;
$('li:lt('+num+')').addClass('red');
}else{
$('li').removeClass('active');
$('li').removeClass('red');
let num = $(this).index()+1;
$('li:lt('+num+')').addClass('active');
}
});
$('li').mouseout(function(){
$('li').removeClass('active');
$('li').removeClass('red');
});
</script>
</body>
</html>