-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (39 loc) · 1.49 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
var SLIDEINDEX = 100
showSlides(SLIDEINDEX)
function showSlides(index) {
// a variável recebe a array formada pelo elementos DOM selecionados pela classe
var slides = document.querySelectorAll(".slide");
var dots = document.querySelectorAll('.dot-navigation');
if (index >= slides.length) SLIDEINDEX = 0;
if (index < 0) SLIDEINDEX = slides.length -1;
for ( var i = 0; i < slides.length; i++) {
slides[i].style.display = 'none';
dots[i].classList.remove('active-dot');
dots[i].style.backgroundColor = '#d6d6d6';
}
slides[SLIDEINDEX].style.display = 'block';
dots[SLIDEINDEX].style.backgroundColor = 'black';
dots[SLIDEINDEX].classList.remove('active-dot');
}
// showSlides + setInterval = os slides mudam sem click
setInterval(function( ){
showSlides(++SLIDEINDEX)
}, 10000)
// addEvenListenter - ao clicar nas setas os slides trocam
document.querySelector('#arrow-prev').addEventListener
("click", function(){
showSlides(--SLIDEINDEX);
})
document.querySelector('#arrow-next').addEventListener
("click", function(){
showSlides(++SLIDEINDEX);
})
// Ao clicar nos pontos os slides também trocam
document.querySelectorAll(".dot-navigation").forEach(function
(element){
element.addEventListener("click", function(){
var dots = Array.prototype.slice.call(this.parentElement.children),
dotIndex = dots.indexOf(element);
showSlides(SLIDEINDEX = dotIndex)
})
})