Skip to content

Commit faa6a32

Browse files
hotfix: Index page not showing content on navigation (#17)
* refactor: moving animate content to outside domcontentloaded * fix: calling animatecontent on spa-content-loaded event
1 parent 37611db commit faa6a32

1 file changed

Lines changed: 33 additions & 27 deletions

File tree

src/pages/index.astro

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ const allTags = [...new Set(allPosts.flatMap(post => post.data.tags || []))].sli
192192
</Layout>
193193

194194
<script>
195+
// Add smooth reveal animations for content after loading
196+
const animateContent = () => {
197+
// Animate hero section
198+
const heroElements = document.querySelectorAll('.hero-text span, .hero-text + p, .hero-text ~ div');
199+
heroElements.forEach((el, index) => {
200+
setTimeout(() => {
201+
el.classList.add('animate-reveal');
202+
}, 100 + (index * 150));
203+
});
204+
205+
// Animate posts with staggered delay
206+
const articles = document.querySelectorAll('article.group');
207+
articles.forEach((article, index) => {
208+
setTimeout(() => {
209+
article.classList.add('animate-reveal');
210+
}, 500 + (index * 150));
211+
});
212+
213+
// Animate topic cards with staggered delay
214+
const topicCards = document.querySelectorAll('a.group.flex.flex-col');
215+
topicCards.forEach((card, index) => {
216+
setTimeout(() => {
217+
card.classList.add('animate-reveal');
218+
}, 800 + (index * 100));
219+
});
220+
};
221+
195222
// Add hover effect for cards on touch devices
196223
document.addEventListener('DOMContentLoaded', () => {
197224
// Check if it's a touch device
@@ -319,33 +346,6 @@ const allTags = [...new Set(allPosts.flatMap(post => post.data.tags || []))].sli
319346
}
320347
});
321348

322-
// Add smooth reveal animations for content after loading
323-
const animateContent = () => {
324-
// Animate hero section
325-
const heroElements = document.querySelectorAll('.hero-text span, .hero-text + p, .hero-text ~ div');
326-
heroElements.forEach((el, index) => {
327-
setTimeout(() => {
328-
el.classList.add('animate-reveal');
329-
}, 100 + (index * 150));
330-
});
331-
332-
// Animate posts with staggered delay
333-
const articles = document.querySelectorAll('article.group');
334-
articles.forEach((article, index) => {
335-
setTimeout(() => {
336-
article.classList.add('animate-reveal');
337-
}, 500 + (index * 150));
338-
});
339-
340-
// Animate topic cards with staggered delay
341-
const topicCards = document.querySelectorAll('a.group.flex.flex-col');
342-
topicCards.forEach((card, index) => {
343-
setTimeout(() => {
344-
card.classList.add('animate-reveal');
345-
}, 800 + (index * 100));
346-
});
347-
};
348-
349349
// Run animations after the loading screen is hidden
350350
const loadingScreen = document.getElementById('loading-screen');
351351
if (loadingScreen) {
@@ -376,6 +376,12 @@ const allTags = [...new Set(allPosts.flatMap(post => post.data.tags || []))].sli
376376
animateContent();
377377
}
378378
});
379+
380+
// call animateContent when the layout finishes inserting SPA content
381+
document.addEventListener('spa-content-loaded', () => {
382+
// small delay to allow inserted DOM to settle
383+
setTimeout(animateContent, 40);
384+
});
379385

380386
// SPA transition handling for homepage
381387
function setupSPATransitions() {

0 commit comments

Comments
 (0)