-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.js
74 lines (69 loc) · 1.56 KB
/
text.js
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
var items=document.getElementsByClassName('item');
var goprebtn=document.getElementById('gopre');
var gonextbtn=document.getElementById('gonext');
var points=document.getElementsByClassName('point');
var point=document.getElementsByClassName('point');
var index=0;//表示第Index张图片在最上面
//清除所有的active
var clearactive=function(){
for(var i=0;i<items.length;i++){
items[i].className='item';
}
for(var i=0;i<items.length;i++){
points[i].className='point';
}
}
//跳到应该去的点和图片
var goindex = function(){
clearactive();
items[index].className='item active';
points[index].className='point active';
}
//去下一张图片
var gonext=function(){
if(index<3)
{
index++;
}
else{index=0;
}
goindex();
}
//去上一张图片
var gopre=function(){
if(index>0)
{
index--;
}
else{index=3;
}
goindex();
}
//给按钮加上相应功能
gonextbtn.addEventListener('click',function(){
gonext();
time=0;
})
goprebtn.addEventListener('click',function(){
gopre();
time=0;
})
//给点点加上相应功能
for(var i=0;i<points.length;i++){
points[i].addEventListener('click',function(){
var pointindex=this.getAttribute('data-index');
index=pointindex;
goindex();
time=0;
})
}
//设置定时器 2000毫秒跳转一次
var time=0;
setInterval(function(){
time++
if(time==20)
{
gonext();
time=0;
}
},100)