-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
275 lines (241 loc) · 7.56 KB
/
script.js
File metadata and controls
275 lines (241 loc) · 7.56 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// ===========================
// PAISY BLOG — INTERACTIONS
// ===========================
// Loading bar
const loadingBar = document.getElementById('loading-bar');
window.addEventListener('load', () => {
if (loadingBar) {
loadingBar.style.width = '100%';
setTimeout(() => { loadingBar.style.opacity = '0'; }, 400);
}
});
// Simulate loading progress
if (loadingBar) {
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 20;
if (progress >= 90) { clearInterval(interval); progress = 90; }
loadingBar.style.width = progress + '%';
}, 150);
}
// ===========================
// NAV — Scroll & Mobile
// ===========================
const nav = document.querySelector('.nav');
const menuBtn = document.querySelector('.nav-menu-btn');
const navLinks = document.querySelector('.nav-links');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
nav.classList.add('scrolled');
} else {
nav.classList.remove('scrolled');
}
}, { passive: true });
if (menuBtn && navLinks) {
menuBtn.addEventListener('click', () => {
navLinks.classList.toggle('open');
const spans = menuBtn.querySelectorAll('span');
if (navLinks.classList.contains('open')) {
spans[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'rotate(-45deg) translate(5px, -5px)';
} else {
spans[0].style.transform = '';
spans[1].style.opacity = '';
spans[2].style.transform = '';
}
});
}
// Close menu on link click
if (navLinks) {
navLinks.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('open');
const spans = menuBtn.querySelectorAll('span');
spans[0].style.transform = '';
spans[1].style.opacity = '';
spans[2].style.transform = '';
});
});
}
// ===========================
// SCROLL REVEAL
// ===========================
const revealElements = document.querySelectorAll('.reveal');
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, { threshold: 0.1, rootMargin: '0px 0px -60px 0px' });
revealElements.forEach(el => revealObserver.observe(el));
// ===========================
// CURSOR GLOW (desktop only)
// ===========================
if (window.matchMedia('(pointer: fine)').matches) {
const cursorGlow = document.createElement('div');
cursorGlow.className = 'cursor-glow';
document.body.appendChild(cursorGlow);
let mouseX = 0, mouseY = 0;
let glowX = 0, glowY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
}, { passive: true });
function animateCursor() {
glowX += (mouseX - glowX) * 0.08;
glowY += (mouseY - glowY) * 0.08;
cursorGlow.style.left = glowX + 'px';
cursorGlow.style.top = glowY + 'px';
requestAnimationFrame(animateCursor);
}
animateCursor();
}
// ===========================
// COUNTER ANIMATION
// ===========================
function animateCounter(el, target, duration = 1500) {
let start = 0;
const startTime = performance.now();
const isFloat = target % 1 !== 0;
function update(currentTime) {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
const current = start + (target - start) * eased;
if (isFloat) {
el.textContent = current.toFixed(1);
} else {
el.textContent = Math.floor(current).toLocaleString();
}
if (progress < 1) requestAnimationFrame(update);
}
requestAnimationFrame(update);
}
const statObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
const value = parseFloat(el.dataset.value);
animateCounter(el, value);
statObserver.unobserve(el);
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat-value[data-value]').forEach(el => {
statObserver.observe(el);
});
// ===========================
// NEWSLETTER FORM
// ===========================
const newsletterForm = document.querySelector('.newsletter-form');
if (newsletterForm) {
newsletterForm.addEventListener('submit', (e) => {
e.preventDefault();
const input = newsletterForm.querySelector('input');
const btn = newsletterForm.querySelector('button');
const originalText = btn.textContent;
if (!input.value || !input.value.includes('@')) {
input.style.borderColor = '#fc5c7d';
input.style.boxShadow = '0 0 0 3px rgba(252, 92, 125, 0.15)';
setTimeout(() => {
input.style.borderColor = '';
input.style.boxShadow = '';
}, 2000);
return;
}
btn.textContent = '✓ Subscribed!';
btn.style.background = 'linear-gradient(135deg, #43e97b, #38f9d7)';
input.value = '';
setTimeout(() => {
btn.textContent = originalText;
btn.style.background = '';
}, 3000);
});
}
// ===========================
// POST CARD HOVER RIPPLE
// ===========================
document.querySelectorAll('.post-card, .featured-card, .topic-card').forEach(card => {
card.addEventListener('click', function (e) {
const ripple = document.createElement('span');
ripple.style.cssText = `
position: absolute;
border-radius: 50%;
background: rgba(124, 92, 252, 0.2);
transform: scale(0);
animation: ripple 0.6s ease-out forwards;
width: 100px;
height: 100px;
left: ${e.offsetX - 50}px;
top: ${e.offsetY - 50}px;
pointer-events: none;
`;
// Inject ripple keyframes once
if (!document.getElementById('ripple-style')) {
const style = document.createElement('style');
style.id = 'ripple-style';
style.textContent = `@keyframes ripple { to { transform: scale(4); opacity: 0; } }`;
document.head.appendChild(style);
}
this.style.position = 'relative';
this.style.overflow = 'hidden';
this.appendChild(ripple);
setTimeout(() => ripple.remove(), 700);
});
});
// ===========================
// TYPING EFFECT (Hero subtitle)
// ===========================
const typingEl = document.getElementById('typing-text');
if (typingEl) {
const phrases = [
'Technology & Innovation',
'Design & Creativity',
'Life & Philosophy',
'Code & Architecture',
];
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
let isPaused = false;
function type() {
const current = phrases[phraseIndex];
if (isPaused) {
isPaused = false;
setTimeout(type, 1200);
return;
}
if (!isDeleting) {
typingEl.textContent = current.substring(0, charIndex + 1);
charIndex++;
if (charIndex === current.length) {
isDeleting = true;
isPaused = true;
}
} else {
typingEl.textContent = current.substring(0, charIndex - 1);
charIndex--;
if (charIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
}
}
setTimeout(type, isDeleting ? 40 : 80);
}
type();
}
// ===========================
// SMOOTH SCROLL for anchor links
// ===========================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const target = document.querySelector(this.getAttribute('href'));
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
});