-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (51 loc) · 1.61 KB
/
Copy pathindex.js
File metadata and controls
61 lines (51 loc) · 1.61 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
56
57
58
59
60
61
/*
* Copyright (c) 2025–present
* PIX4ME Authors
*
* All rights reserved.
*/
(() => {
const body = document.body;
const html = document.documentElement;
let currentScroll = window.scrollY || window.pageYOffset;
let targetScroll = currentScroll;
let isScrolling = false;
const ease = 0.15;
function smoothScroll() {
currentScroll += (targetScroll - currentScroll) * ease;
window.scrollTo(0, currentScroll);
if (Math.abs(targetScroll - currentScroll) > 0.5) {
requestAnimationFrame(smoothScroll);
} else {
isScrolling = false;
}
}
window.addEventListener("wheel", (e) => {
e.preventDefault();
targetScroll += e.deltaY;
targetScroll = Math.max(0, Math.min(targetScroll, html.scrollHeight - window.innerHeight));
if (!isScrolling) {
isScrolling = true;
requestAnimationFrame(smoothScroll);
}
}, { passive: false });
window.addEventListener("keydown", (e) => {
let delta = 0;
switch(e.key) {
case "ArrowDown": delta = 40; break;
case "ArrowUp": delta = -40; break;
case "PageDown": delta = window.innerHeight; break;
case "PageUp": delta = -window.innerHeight; break;
case "Home": delta = -targetScroll; break;
case "End": delta = html.scrollHeight; break;
default: return;
}
e.preventDefault();
targetScroll += delta;
targetScroll = Math.max(0, Math.min(targetScroll, html.scrollHeight - window.innerHeight));
if (!isScrolling) {
isScrolling = true;
requestAnimationFrame(smoothScroll);
}
});
})();