-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslide.js
46 lines (39 loc) · 1.11 KB
/
slide.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
{
let slide=document.querySelectorAll('.slide');
let dots=document.querySelectorAll('.dot');
let p=0;
function autoAction(){
setTimeout(function(item){
slide.forEach(function(s){
s.classList.remove('active');
});
dots.forEach(function(s){
s.classList.remove('active');
});
slide[p].classList.add('active');
dots[p].classList.add('active');
p++;
if(p===slide.length){
p=0;
}
autoAction();
},6000);
}
autoAction();
function manualAction(manual){
slide.forEach(function(s){
s.classList.remove('active');
});
dots.forEach(function(s){
s.classList.remove('active');
});
slide[manual].classList.add('active');
dots[manual].classList.add('active');
}
dots.forEach(function(btn,i){
btn.addEventListener('click',function(){
manualAction(i);
p=i;
});
});
}