Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (38 loc) · 1.29 KB
/
Copy pathapp.js
File metadata and controls
55 lines (38 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const upbtn = document.querySelector('.up-button')
const downbtn = document.querySelector('.down-button')
const container = document.querySelector('.container')
const sidebar = document.querySelector('.sidebar')
const mainSlide = document.querySelector('.main-slide')
const sliderCount = mainSlide.querySelectorAll('div').length
let activeSlideIndex = 0
sidebar.style.top = `-${(sliderCount - 1 )* 100}vh` //Обратные кавычки
upbtn.addEventListener('click', () => {
ChangeSlide('up')
})
downbtn.addEventListener('click', () => {
ChangeSlide('down')
})
document.addEventListener('keydown',
event => {
if (event.key === 'ArrowUp') {
ChangeSlide('up')
} else if (event.key === 'ArrowDown') {
ChangeSlide('down')
}
})
function ChangeSlide(direction) {
if (direction === 'up') {
activeSlideIndex++
if (activeSlideIndex === sliderCount) {
activeSlideIndex = 0
}
} else {
activeSlideIndex--
if (activeSlideIndex < 0) {
activeSlideIndex = sliderCount - 1
}
}
const heigth = container.clientHeight
mainSlide.style.transform = `translateY(-${(activeSlideIndex * heigth)}px)`
sidebar.style.transform = `translateY(${(activeSlideIndex * heigth)}px)`
}