-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (64 loc) · 1.83 KB
/
index.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
let tabImg = document.querySelectorAll('.images > div');
let leftArrow = document.querySelector('.fleches > i.fa-chevron-left');
let rightArrow = document.querySelector('.fleches > i.fa-chevron-right');
let imgActive = 0;
tabImg[imgActive].classList.add('show');
//hide all pictures except the first
for(let i = 1; i<tabImg.length; i++){
tabImg[i].classList.add('hidden');
}
//function next picture
const next = function(){
tabImg[imgActive].classList.remove('show');
tabImg[imgActive].classList.add('hidden');
imgActive ++;
if(imgActive >= tabImg.length){
imgActive = 0;
}
tabImg[imgActive].classList.remove('hidden');
setTimeout(()=>{
tabImg[imgActive].classList.add('show'),
600;
})
}
//function precedent picture
const before = function(){
tabImg[imgActive].classList.remove('show');
tabImg[imgActive].classList.add('hidden');
imgActive --;
if(imgActive < 0){
imgActive = tabImg.length-1;
}
tabImg[imgActive].classList.remove('hidden');
setTimeout(()=>{
tabImg[imgActive].classList.add('show'),
600
})
}
//click sur bouton right
rightArrow.addEventListener('click', function(){
next();
})
//click sur bouton left
leftArrow.addEventListener('click', function(){
before();
})
let play;
document.querySelector('#playButton').addEventListener('click', function(){
play = setInterval(next, 2000);
})
document.querySelector('#pauseButton').addEventListener('click', function(){
clearInterval(play);
})
window.addEventListener('keydown', function(e){
if(e.key == 'ArrowRight'){
next();
console.log(e.key);
}
})
window.addEventListener('keydown', function(e){
if(e.key == 'ArrowLeft'){
before();
console.log(e.key);
}
})