-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (108 loc) · 3.67 KB
/
script.js
File metadata and controls
133 lines (108 loc) · 3.67 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('section');
let currentSectionIndex = 0;
let isAnimating = false;
function switchSection(direction) {
if (isAnimating) return;
const nextIndex = currentSectionIndex + direction;
// Bounds check
if (nextIndex < 0 || nextIndex >= sections.length) return;
// Start Transition
isAnimating = true;
const currentSection = sections[currentSectionIndex];
const nextSection = sections[nextIndex];
// Sequence:
// 1. Fade out current
// 2. Wait
// 3. Fade in next
// Step 1: Fade out current
currentSection.classList.add('fading-out');
// Step 2: Wait for fade out
setTimeout(() => {
currentSection.classList.remove('active', 'fading-out');
nextSection.classList.add('active'); // Display block
nextSection.classList.add('fading-out'); // Ensure it starts hidden
// Step 3: Fade In Next
// Slight delay to ensure DOM update
setTimeout(() => {
nextSection.classList.remove('fading-out');
// Complete
setTimeout(() => {
isAnimating = false;
}, 800); // Wait for fade in
}, 50);
}, 800); // Match CSS transition time
currentSectionIndex = nextIndex;
}
// Scroll Listener
window.addEventListener('wheel', (e) => {
// Simple threshold to avoid sensitive trackpads triggering too easily
if (Math.abs(e.deltaY) < 20) return;
if (e.deltaY > 0) {
// Scroll Down -> Next
switchSection(1);
} else {
// Scroll Up -> Prev
switchSection(-1);
}
}, { passive: false });
// Link Interception for Smooth Transition to Gallery (List)
const galleryLink = document.getElementById('link-gallery');
if (galleryLink) {
galleryLink.addEventListener('click', (e) => {
e.preventDefault();
// Fade out current body
document.body.style.transition = 'opacity 0.8s ease';
document.body.style.opacity = '0';
// Navigate after fade
setTimeout(() => {
window.location.href = 'list/'; // Goes to list/index.html
}, 800);
});
}
// Link Interception for Essay
const essayLink = document.getElementById('link-essay');
if (essayLink) {
essayLink.addEventListener('click', (e) => {
e.preventDefault();
document.body.style.transition = 'opacity 0.8s ease';
document.body.style.opacity = '0';
setTimeout(() => {
window.location.href = 'essay/'; // Goes to essay/index.html
}, 800);
});
}
// Initial State Check
sections[0].classList.add('active');
sections.forEach(sec => sec.classList.remove('fading-out'));
// --- MOBILE SWIPE SUPPORT & TEXT UPDATE ---
// 1. Update Text
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth < 768;
if (isMobile) {
const scrollText = document.querySelector('.scroll-indicator .text');
if (scrollText) scrollText.textContent = 'SWIPE';
}
// 2. Swipe Gestures
let touchStartY = 0;
let touchEndY = 0;
const minSwipeDistance = 50;
window.addEventListener('touchstart', (e) => {
touchStartY = e.changedTouches[0].screenY;
}, { passive: false });
window.addEventListener('touchend', (e) => {
touchEndY = e.changedTouches[0].screenY;
handleSwipe();
}, { passive: false });
function handleSwipe() {
const distance = touchStartY - touchEndY;
if (Math.abs(distance) > minSwipeDistance) {
if (distance > 0) {
// Swipe Up -> Next (Scroll Down)
switchSection(1);
} else {
// Swipe Down -> Prev (Scroll Up)
switchSection(-1);
}
}
}
});