-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
182 lines (152 loc) · 4.92 KB
/
script.js
File metadata and controls
182 lines (152 loc) · 4.92 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Fade-in on scroll
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
});
document.querySelectorAll('.fade-in, .fade-in-delay, .fade-in-delay2, .fade-in-delay3, .fade-in-up').forEach(el => {
observer.observe(el);
});
// === Sci-Fi Line Activation ===
const sciFiLines = document.querySelectorAll('.sci-fi-line');
const heroBanner = document.querySelector('#hero-banner');
const contentContainer = document.querySelector('.container');
// Detect when hero is NOT visible
const bannerObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (!entry.isIntersecting) {
sciFiLines.forEach(line => line.classList.add('active'));
contentContainer.classList.add('visible');
document.body.classList.add('dark-bg'); // <– new
} else {
sciFiLines.forEach(line => line.classList.remove('active'));
contentContainer.classList.remove('visible');
document.body.classList.remove('dark-bg'); // <– new
}
});
}, { threshold: 0.7 });
bannerObserver.observe(heroBanner);
// Immediately activate sci-fi lines if page loads mid-scroll
window.addEventListener('load', () => {
const heroRect = heroBanner.getBoundingClientRect();
if (heroRect.bottom <= 0) {
sciFiLines.forEach(line => line.classList.add('active'));
contentContainer.classList.add('visible');
}
});
document.querySelectorAll('.timeline li').forEach(card => {
card.addEventListener('mousemove', e => {
const rect = card.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const cx = rect.width / 2;
const cy = rect.height / 2;
const dx = (x - cx) / cx;
const dy = (y - cy) / cy;
card.style.transform = `rotateX(${-dy * 5}deg) rotateY(${dx * 5}deg) scale(1.02)`;
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'rotateX(0deg) rotateY(0deg) scale(1)';
});
});
const fonts = [
"'Orbitron', sans-serif",
"'Playfair Display', serif",
"'VT323', monospace",
"'Archivo Black', sans-serif",
"'Cutive Mono', monospace"
];
const defaultFont = "'Archivo Black', sans-serif";
const fontWords = document.querySelectorAll('.font-word');
let scrollTimeout = null;
let cycling = false;
let cycleInterval = null;
// Randomize each word's font
function cycleFonts() {
fontWords.forEach(word => {
const randomFont = fonts[Math.floor(Math.random() * fonts.length)];
word.style.fontFamily = randomFont;
word.classList.add('cycling');
});
}
// Gracefully fade each word back to default font with a random delay
function resetFontsSmooth() {
fontWords.forEach((word, i) => {
const delay = Math.random() * 400 + 100;
setTimeout(() => {
word.style.fontFamily = defaultFont;
word.classList.remove('cycling');
}, delay);
});
}
// Start cycling
function startFontCycle() {
if (cycling) return;
cycling = true;
cycleInterval = setInterval(cycleFonts, 60);
}
// Stop cycling
function stopFontCycle() {
cycling = false;
clearInterval(cycleInterval);
resetFontsSmooth();
}
// Scroll event handling
window.addEventListener('scroll', () => {
startFontCycle();
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
stopFontCycle();
}, 60); // Delay after scrolling stops
});
const canvas = document.getElementById('starfield');
const ctx = canvas.getContext('2d');
let stars = [];
const STAR_COUNT = 100;
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
function initStars() {
stars = [];
for (let i = 0; i < STAR_COUNT; i++) {
stars.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
r: Math.random() * 1.2 + 0.3,
d: Math.random() * 0.05 + 0.01,
});
}
}
function drawStars() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#01c9c9';
stars.forEach(star => {
ctx.beginPath();
ctx.arc(star.x, star.y, star.r, 0, Math.PI * 2);
ctx.fill();
});
}
function moveStars() {
stars.forEach(star => {
star.y += star.d;
if (star.y > canvas.height) {
star.y = 0;
star.x = Math.random() * canvas.width;
}
});
}
function animateStars() {
moveStars();
drawStars();
requestAnimationFrame(animateStars);
}
window.addEventListener('resize', () => {
resizeCanvas();
initStars();
});
resizeCanvas();
initStars();
animateStars();