-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarousel.js
More file actions
40 lines (32 loc) · 1.29 KB
/
carousel.js
File metadata and controls
40 lines (32 loc) · 1.29 KB
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
(function () {
var previousButton = document.querySelector('.interests__previous-button');
var nextButton = document.querySelector('.interests__next-button');
var navigation = document.querySelector('.interests__navigation');
nextButton.addEventListener('click', function () {
clearInterval(intervalId);
activateNextSlide()
});
previousButton.addEventListener('click', function () {
clearInterval(intervalId);
activatePreviousSlide()
});
var intervalId = setInterval(function () {
activateNextSlide()
}, 2000);
function activateNextSlide() {
var element = document.querySelector('.interests-items img:first-child');
element.parentElement.appendChild(element);
var current = navigation.querySelector('.active');
var next = current.nextElementSibling || navigation.querySelector('span');
current.classList.remove('active');
next.classList.add('active');
}
function activatePreviousSlide() {
var element = document.querySelector('.interests-items img:last-child');
element.parentElement.prepend(element);
var current = navigation.querySelector('.active');
var previous = current.previousElementSibling || navigation.querySelector('span:last-child');
current.classList.remove('active');
previous.classList.add('active');
}
})()