Skip to content

Commit ba23f19

Browse files
committed
Added Script
1 parent 6dee03b commit ba23f19

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Double Vertical Slider/script.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const sliderContainer = document.querySelector('.slider-container');
2+
const slideRight = document.querySelector('.right-slide');
3+
const slideLeft = document.querySelector('.left-slide');
4+
const upButton = document.querySelector('.up-button');
5+
const downButton = document.querySelector('.down-button');
6+
const slidesLength = slideRight.querySelectorAll('div').length;
7+
8+
let activeSlideIndex = 0;
9+
10+
slideLeft.style.top = `-${(slidesLength - 1) * 100}vh`;
11+
12+
upButton.addEventListener('click', () => changeSlide('up'));
13+
downButton.addEventListener('click', () => changeSlide('down'));
14+
15+
const changeSlide = (direction) => {
16+
const sliderHeight = sliderContainer.clientHeight;
17+
if (direction === 'up') {
18+
activeSlideIndex++;
19+
if (activeSlideIndex > slidesLength - 1) {
20+
activeSlideIndex = 0;
21+
}
22+
} else if (direction === 'down') {
23+
activeSlideIndex--;
24+
if (activeSlideIndex < 0) {
25+
activeSlideIndex = slidesLength - 1;
26+
}
27+
}
28+
29+
slideRight.style.transform = `translateY(-${
30+
activeSlideIndex * sliderHeight
31+
}px)`;
32+
slideLeft.style.transform = `translateY(${
33+
activeSlideIndex * sliderHeight
34+
}px)`;
35+
};

0 commit comments

Comments
 (0)