-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn.html
133 lines (116 loc) · 2.87 KB
/
fn.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
img {
border: 0;
}
#container {
width: 520px;
height: 280px;
position: relative;
margin: 100px auto;
}
#imgs img {
display: none;
}
#imgs .selected {
display: block;
}
#nav {
position: absolute;
right: 10px;
bottom: 10px;
}
#narrow div, #nav li {
width: 20px;
height: 20px;
margin-right: 5px;
background: black;
color: white;
text-align: center;
line-height: 20px;
float: left;
cursor: pointer;
}
#nav .selected {
background: orange;
}
#narrow {
position: absolute;
left: 10px;
bottom: 10px;
}
</style>
</head>
<body>
<div id="container">
<div id="imgs">
<img src="img/1.jpg" alt="" class="selected"/>
<img src="img/2.jpg" alt=""/>
<img src="img/3.jpg" alt=""/>
<img src="img/4.jpg" alt=""/>
</div>
<ul id="nav">
<li class="selected">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div id="narrow">
<div id="left"><</div>
<div id="right">></div>
</div>
</div>
<script src="jquery-1.11.2.js"></script>
<script>
$(function () {
var nowIndex = 0;
var timer;
function change() {
$('#nav li').eq(nowIndex).addClass("selected").siblings().removeClass("selected");
$("#imgs img").eq(nowIndex).addClass("selected").siblings().removeClass("selected");
}
$('#nav li').on("mouseover", function () {
nowIndex = $(this).index();
change();
});
$("#narrow div").on("click", function () {
if ($(this).attr("id") == "left") {
nowIndex--;
if (nowIndex == -1) {
nowIndex = $("#nav li").length - 1;
}
} else {
nowIndex++;
//这是nav下的li,长度是4,如果是nav长度是1
if (nowIndex == $("#nav li").length - 1) {
nowIndex = 0;
}
}
change();
});
function play(){
timer = setInterval(function(){
$("#narrow #right").trigger("click");
},1000);
}
$("#container").hover(function(){
clearInterval(timer);
},function(){
play();
});
play();
})
</script>
</body>
</html>