-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (31 loc) · 1.07 KB
/
app.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
const upBtn = document.querySelector('.up-button')
const downBtn = document.querySelector('.down-button')
const sidebar = document.querySelector('.sidebar')
const mainSlide = document.querySelector('.main-slide')
const slidesCount = mainSlide.querySelectorAll('div').length
const container = document.querySelector('.container')
let activeSlideIndex = 0
sidebar.style.top = `-${(slidesCount - 1) * 100}vh`
upBtn.addEventListener('click', () => {
changeSlide('up')
}
)
downBtn.addEventListener('click', () => {
changeSlide('down')
})
function changeSlide(direction) {
if (direction === 'up') {
activeSlideIndex++
if (activeSlideIndex === slidesCount) {
activeSlideIndex = 0
}
} else if (direction === 'down') {
activeSlideIndex--
if (activeSlideIndex < 0) {
activeSlideIndex = slidesCount - 1
}
}
const height = container.clientHeight
mainSlide.style.transform = `translateY(-${activeSlideIndex * height}px)`
sidebar.style.transform = `translateY(${activeSlideIndex * height}px)`
}