-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.js
46 lines (36 loc) · 1.32 KB
/
slider.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
const slider = document.querySelector ("#slider");
let sliderSection = document.querySelectorAll(".slider__section");
let sliderSectionLast = sliderSection[sliderSection.length -1];
const btnLeft = document.querySelector ("#btn-left");
const btnRight = document.querySelector ("#btn-right");
slider.insertAdjacentElement('afterbegin', sliderSectionLast);
function Next() {
let sliderSectionFirst = document.querySelectorAll(".slider__section")[0];
slider.stylemarginLeft = "-200%";
slider.style.transition = "all 2.5s";
setTimeout (function() {
slider.style.transition = "none";
slider.insertAdjacentElement ('beforeend', sliderSectionFirst);
slider.stylemarginLeft = "-100%";
}, 500);
}
function Prev() {
let sliderSection = document.querySelectorAll(".slider__section");
let sliderSectionLast = sliderSection[sliderSection.lenght -1];
slider.stylemarginLeft = "0%";
slider.style.transition = "all 2.5s";
setTimeout (function(){
slider.style.transition = "none";
slider.insertAdjacentElement('afterbegin', sliderSectionLast);
slider.stylemarginLeft = "-100%";
}, 500);
}
btnRight.addEventListener('click', function(){
Next();
});
btnLeft.addEventListener('click', function(){
Prev();
});
setInterval(function(){
Next();
}, 2000);