-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
118 lines (91 loc) · 3.78 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// let navDialog = document.getElementById('nav-dialog');
// function handleMenu() {
// navDialog.classList.toggle('hidden');
// }
// const initialTranslateLTR = -48*4;
// const initialTranslateRTL = 36*4;
// function setupIntersectionObserver(element, isLTR, speed) {
// const intersectionCallback = (entries) => {
// const isIntersecting = entries[0].isIntersecting;
// if(isIntersecting) {
// document.addEventListener('scroll', scrollHandler);
// } else {
// document.removeEventListener('scroll', scrollHandler);
// }
// }
// const intersectionObserver = new IntersectionObserver(intersectionCallback);
// intersectionObserver.observe(element);
// function scrollHandler() {
// const translateX = (window.innerHeight - element.getBoundingClientRect().top) * speed;
// let totalTranslate = 0;
// if(isLTR) {
// totalTranslate = translateX + initialTranslateLTR;
// } else {
// totalTranslate = -(translateX + initialTranslateRTL);
// }
// element.style.transform = `translateX(${totalTranslate}px)`;
// }
// }
// const line1 = document.getElementById('line1');
// const line2 = document.getElementById('line2');
// const line3 = document.getElementById('line3');
// const line4 = document.getElementById('line4');
// setupIntersectionObserver(line1, true, 0.15);
// setupIntersectionObserver(line2, false, 0.15);
// setupIntersectionObserver(line3, true, 0.15);
// setupIntersectionObserver(line4, true, 0.8);
// const dtElements = document.querySelectorAll('dt');
// dtElements.forEach(element => {
// element.addEventListener('click', () => {
// const ddId = element.getAttribute('aria-controls');
// const ddElement = document.getElementById(ddId);
// const ddArrowIcon = element.querySelectorAll('i')[0];
// ddElement.classList.toggle('hidden');
// ddArrowIcon.classList.toggle('-rotate-180');
// })
// })
function handleMenu() {
navDialog.classList.toggle('hidden');
}
const initialTranslateLTR = -48*4;
const initialTranslateRTL = 36*4;
function setupIntersectionObserver(element, isLTR, speed) {
const intersectionCallback = (entries) => {
const isIntersecting = entries[0].isIntersecting;
if(isIntersecting) {
document.addEventListener('scroll', scrollHandler);
} else {
document.removeEventListener('scroll', scrollHandler);
}
}
const intersectionObserver = new IntersectionObserver(intersectionCallback);
intersectionObserver.observe(element);
function scrollHandler() {
const translateX = (window.innerHeight - element.getBoundingClientRect().top) * speed;
let totalTranslate = 0;
if(isLTR) {
totalTranslate = translateX + initialTranslateLTR;
} else {
totalTranslate = -(translateX + initialTranslateRTL);
}
element.style.transform = `translateX(${totalTranslate}px)`;
}
}
const line1 = document.getElementById('line1');
const line2 = document.getElementById('line2');
const line3 = document.getElementById('line3');
const line4 = document.getElementById('line4');
setupIntersectionObserver(line1, true, 0.15);
setupIntersectionObserver(line2, false, 0.15);
setupIntersectionObserver(line3, true, 0.15);
setupIntersectionObserver(line4, true, 0.8);
const dtElements = document.querySelectorAll('dt');
dtElements.forEach(element => {
element.addEventListener('click', () => {
const ddId = element.getAttribute('aria-controls');
const ddElement = document.getElementById(ddId);
const ddArrowIcon = element.querySelectorAll('i')[0];
ddElement.classList.toggle('hidden');
ddArrowIcon.classList.toggle('-rotate-180');
})
})