-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
99 lines (93 loc) · 2 KB
/
Copy pathtest.js
File metadata and controls
99 lines (93 loc) · 2 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var timer = null,
index = 0,
img_count = 4,
locatArr = [0, -720, -1440, -2160,-2880];
var box = document.getElementsByClassName('box')[0],
dot = document.getElementsByClassName('dot')[0];
/**
*跳转到某张图片
*@function moveto
*@param location 索引值,具体位置存储在locatArr数组中
*@return none
*/
function moveto(location) {
box.style.left = locatArr[location] + 'px';
}
/**
*图片展示函数,根据索引值到达相应地方
*@param none
*@return none
*/
function disPlay () {
if(index == img_count - 1){
moveto(0);
index = 0;
}else{
moveto(++index);
}
}
/**
*上一张/下一章图片
*@param none
*@return none
*/
function lastPlay () {
if(index == 0){
moveto(3);
index = 3;
}else{
moveto(--index);
}
}
function nextPlay () {
if(index == 3){
moveto(0);
index = 0;
}else{
moveto(++index);
}
}
/**
*绑定时间,包括小圆点、箭头的click事件
*@function bindEvent
*@param none
*@return none
*/
function bindEvent() {
var li = dot.getElementsByTagName('li');
var next = document.getElementsByClassName('next')[0];
var last = document.getElementsByClassName('last')[0];
next.addEventListener('click',function () {
clearInterval(timer);
nextPlay();
timer = setInterval(disPlay,2000);
});
last.addEventListener('click',function() {
clearInterval(timer);
lastPlay();
timer = setInterval(disPlay,2000);
});
for(var i = 0; i < 4; i++){
(function (j) {
li[j].addEventListener('click',function () {
clearInterval(timer);
index = j;
moveto(index);
timer = setInterval(disPlay,2000);
})
}(i))
}
}
function start() {
timer = setInterval(disPlay,2000);
let timerDot = setInterval(function () {
let dots = document.getElementsByClassName('dot')[0];
let singledot = dots.getElementsByTagName('li');
for(var i = 0; i < 4; i++){
singledot[i].className = '';
}
singledot[index].className = 'act';
},20)
bindEvent();
}
start();