-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (29 loc) · 910 Bytes
/
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
// Opdracht: Image caroussel
// Wat heb je nodig?
// - lijst van images
// - click events en referentie naar een img element
// - teller die bijhoudt op welke positie we zitten
const images = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg'];
let position = 0
const image = document.querySelector('img');
const left = document.querySelector('.left');
const right = document.querySelector('.right');
left.addEventListener('click', previous);
right.addEventListener('click', next);
function next() {
image.src = './images/' + images[getNextPosition()];
console.log(img.src);
}
function previous() {
image.src = './images/' + images[getPreviousPosition()];
}
function getNextPosition() {
position++;
if(position == images.length) position = 0;
return position;
}
function getPreviousPosition() {
position--;
if(position == 0) position = 3;
return position;
}