forked from sidradchandran/SV-Carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
33 lines (33 loc) · 1.2 KB
/
script.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
var BG = (function(d,w){
if(!typeof w || !typeof d) return;
let options;
let interval;
init = function(obj){
options = {};
obj = (obj || {});
options.interval = obj.hasOwnProperty('interval') ? obj.interval : 7000;
options.count = obj.hasOwnProperty('count') ? obj.count : document.querySelectorAll('.slide').length;
return this;
}
startSlide = function(){
if(!typeof options) return;
let index = 1;
interval = w.setInterval( () => {
if(index <= parseInt(options.count) - 1){
let element = d.querySelector('.slide-active:nth-child('+index+')');
element.classList.remove('slide-active');
element.nextElementSibling.classList.add('slide-active');
index++;
}
else{
d.querySelector('.slide-active:nth-child('+index+')').classList.remove('slide-active');
d.querySelector('.slide:nth-child(1)').classList.add('slide-active');
index = 1;
}
},options.interval);
};
stopSlide = function(){
w.clearInterval(interval);
};
return this;
})(document, window)