-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
59 lines (50 loc) · 1.67 KB
/
script.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const slider = document.querySelector('.slider');
const slides = document.querySelectorAll('section');
let currentIndex = 0;
function setPositionByIndex() {
const translateValue = currentIndex * -window.innerWidth;
slider.style.transform = `translateX(${translateValue}px)`;
}
function handleScroll(event) {
const delta = event.deltaY || event.detail || event.wheelDelta;
if (delta > 0) {
// Scrolling down
if (currentIndex < slides.length - 1) {
currentIndex++;
setPositionByIndex();
}
} else {
// Scrolling up
if (currentIndex > 0) {
currentIndex--;
setPositionByIndex();
}
}
}
// Listen for scroll events
window.addEventListener('wheel', handleScroll, { passive: true });
window.addEventListener('keydown', (event) => {
if (event.key === 'ArrowDown' || event.key === 'ArrowRight') {
// Scroll down or right
if (currentIndex < slides.length - 1) {
currentIndex++;
setPositionByIndex();
}
} else if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') {
// Scroll up or left
if (currentIndex > 0) {
currentIndex--;
setPositionByIndex();
}
}
});
// Set the initial position on load
window.onload = setPositionByIndex;
function toggleMenu() {
const menu = document.getElementById('menu');
menu.classList.toggle('open');
}
window.onscroll = function() {
const scrollProgress = document.documentElement.scrollTop / (document.documentElement.scrollHeight - window.innerHeight) * 100;
document.getElementById('progress-bar').style.width = scrollProgress + "%";
};