-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaro.js
69 lines (62 loc) · 2.07 KB
/
caro.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
var slideIndex,slides,dots,captiontext;
function initGallery(){
slideIndex=0;
slides=document.getElementsByClassName("imageholder");
slides[slideIndex] .style.opacity="1";
captiontext=document.querySelector(".captionholder .captiontext");
captiontext.innerText=slides[slideIndex].querySelector(".captiontext").innerText;
dots=[];
var dotscontainer=document.getElementById("dotscontainer");
for(var i=0;i<slides.length;i++){
var dot=document.createElement("span");
dot.classList.add("dots");
dot.setAttribute("onClick","moveSlide("+i+")");
dotscontainer.append(dot);
dots.push(dot);
dots[slideIndex].classList.add("active");
}
}
initGallery();
function plusSlide(n){
moveSlide(slideIndex+n);
}
function moveSlide(n){
var i,current,next;
var moveSlideAnimClass={
forCurrent:"",forNext:""
}
var slideTextAnimClass;
if(n>slideIndex){
if(n>=slides.length){n=0;}
moveSlideAnimClass.forCurrent="moveLeftCurrentSlide";
moveSlideAnimClass.forNext="moveLeftNextSlide";
slideTextAnimClass="slidetextfromtop";
}else if(n<slideIndex){
if(n<0){n=slides.length-1;
}
moveSlideAnimClass.forCurrent="moveRightCurrentSlide";
moveSlideAnimClass.forNext="moveRightNextSlide";
slideTextAnimClass="slidetextfrombottom";
}
if(n!=slideIndex){
next=slides[n];
current=slides[slideIndex];
for(i=0;i<slides.length;i++){
slides[i].className="imageholder";
slides[i].style.opacity=0;
dots[i].classList.remove("active");
}
current.classList.add(moveSlideAnimClass.forCurrent);
next.classList.add(moveSlideAnimClass.forNext);
dots[n].classList.add("active");
slideIndex=n;
}
captiontext.style.display="none";
captiontext.className="captiontext"+slideTextAnimClass;
captiontext.innerText=slides[n].querySelector(".captiontext").innerText;
captiontext.style.display="block";
}var timer=null;
function setTimer(){
timer=setInterval(function(){plusSlide(1);},3000)
}
setTimer();