-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (56 loc) · 2.39 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const isMobile = window.innerWidth <= 768;
const content = document.querySelector('.content');
if (!isMobile) {
window.addEventListener('wheel', function (e) {
e.preventDefault();
content.scrollLeft += e.deltaY;
}, { passive: false });
content.addEventListener('scroll', function () {
let scrollX = content.scrollLeft;
document.querySelector('.layer-1').style.backgroundPosition = `${-scrollX * 0.05}px 0`;
document.querySelector('.layer-2').style.backgroundPosition = `${-scrollX * 0.1}px 0`;
document.querySelector('.layer-3').style.backgroundPosition = `${-scrollX * 0.15}px 0`;
document.querySelector('.layer-4').style.backgroundPosition = `${-scrollX * 0.2}px 0`;
document.querySelector('.layer-5').style.backgroundPosition = `${-scrollX * 0.25}px 0`;
document.querySelector('.layer-6').style.backgroundPosition = `${-scrollX * 0.3}px 0`;
});
}
let isDown = false;
let startX, scrollLeft;
content.addEventListener("mousedown", (e) => {
isDown = true;
startX = e.pageX - content.offsetLeft;
scrollLeft = content.scrollLeft;
});
content.addEventListener("mouseleave", () => isDown = false);
content.addEventListener("mouseup", () => isDown = false);
content.addEventListener("mousemove", (e) => {
if (!isDown) return;
e.preventDefault();
const x = e.pageX - content.offsetLeft;
const walk = (x - startX) * 2;
content.scrollLeft = scrollLeft - walk;
});
if (isMobile) {
content.addEventListener("touchstart", (e) => {
startX = e.touches[0].pageX - content.offsetLeft;
scrollLeft = content.scrollLeft;
});
content.addEventListener("touchmove", (e) => {
e.preventDefault();
const x = e.touches[0].pageX - content.offsetLeft;
const walk = (x - startX) * 2;
content.scrollLeft = scrollLeft - walk;
});
}
function matchBoxHeights() {
const statBox = document.querySelector('.stat-box');
const aboutBox = document.querySelector('.about-box');
if (statBox && aboutBox) {
const maxHeight = Math.max(statBox.scrollHeight, aboutBox.scrollHeight);
statBox.style.height = maxHeight + "px";
aboutBox.style.height = maxHeight + "px";
}
}
window.addEventListener("load", matchBoxHeights);
window.addEventListener("resize", matchBoxHeights);