-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
91 lines (83 loc) · 2.59 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
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
// -----Variables-----
var slides = document.querySelectorAll('.slide');
var rbtn = document.querySelectorAll('.rad-btn');
var leftArrow = document.querySelector('.left');
var rightArrow = document.querySelector('.right');
var slideInt; // Store On Going Timer
var intTime = 5000;
// -----Iterate All Radio Navigation Buttons-----
rbtn.forEach(function(item, index){
// Click Event for Buttons
item.addEventListener('click', function(){
manButtonNav(index);
});
});
// -----Click Events for Arrows-----
// Right Arrow
rightArrow.addEventListener('click', function(e){
e.preventDefault();
nextSlide();
clrInterval();
});
// Left Arrow
leftArrow.addEventListener('click', function(e){
e.preventDefault();
prevSlide();
clrInterval();
});
// -----Function for Radio Navigation-----
function manButtonNav(index){
for(var i = 0; i < slides.length; i++){
// Set Slide and Radio Navigation Button
if(i !== index){
slides[i].classList.remove('curr');
rbtn[i].classList.remove('active');
}
else{
slides[index].classList.add('curr');
rbtn[index].classList.add('active');
}
}
clrInterval();
}
// -----Function for the Next Slide-----
function nextSlide(){
var curr = document.querySelector('.curr');
var active = document.querySelector('.active');
// Unset Current Slide and Radio Button
curr.classList.remove('curr');
active.classList.remove('active');
// Set Next Slide and Radio Button
if(curr.nextElementSibling){
curr.nextElementSibling.classList.add('curr');
active.nextElementSibling.classList.add('active');
}
else{
slides[0].classList.add('curr');
rbtn[0].classList.add('active');
}
}
// -----Function for the Previous Slide-----
function prevSlide(){
var curr = document.querySelector('.curr');
var active = document.querySelector('.active');
// Unset Current Slide and Radio Button
curr.classList.remove('curr');
active.classList.remove('active');
// Set Previous Slide and Radio Button
if(curr.previousElementSibling){
curr.previousElementSibling.classList.add('curr');
active.previousElementSibling.classList.add('active');
}
else{
slides[slides.length - 1].classList.add('curr');
rbtn[rbtn.length - 1].classList.add('active');
}
}
// -----Function for Clear Interval-----
function clrInterval(){
clearInterval(slideInt);
slideInt = setInterval(nextSlide, intTime);
}
// -----Automatic Slide Navigation-----
slideInt = setInterval(nextSlide, intTime);