-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (75 loc) · 3.25 KB
/
Copy pathscript.js
File metadata and controls
87 lines (75 loc) · 3.25 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
document.addEventListener('DOMContentLoaded', () => {
// Mobile Menu Toggle
const mobileBtn = document.querySelector('.mobile-menu-btn');
const nav = document.querySelector('.main-nav');
if (mobileBtn) {
mobileBtn.addEventListener('click', () => {
nav.classList.toggle('nav-open');
});
}
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
// Close mobile menu if open
if (nav.classList.contains('nav-open')) {
nav.classList.remove('nav-open');
}
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Expand/Collapse Side Stories
const readMoreBtns = document.querySelectorAll('.read-more-btn');
readMoreBtns.forEach(btn => {
btn.addEventListener('click', () => {
const content = btn.nextElementSibling;
const isHidden = content.classList.contains('hidden');
if (isHidden) {
content.classList.remove('hidden');
btn.textContent = 'Read Less';
} else {
content.classList.add('hidden');
btn.textContent = 'Read Full Teaser';
}
});
});
// Intersection Observer for Mist Reveal Animation
const observerOptions = {
threshold: 0.15,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('in-view');
observer.unobserve(entry.target); // Only animate once
}
});
}, observerOptions);
// Apply animation classes and delays
const loreCards = document.querySelectorAll('.lore-card');
loreCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 200}ms`; // Staggered delay
observer.observe(card);
});
// Also observe other animated elements if needed, or just the lore cards as requested
// For consistency, let's observe story previews too but without the heavy mist effect (unless added to CSS)
// The user specifically asked for Lore section mist reveal.
// We can reuse the observer for other elements if we want them to fade in simply.
const otherAnimatedElements = document.querySelectorAll('.story-preview');
otherAnimatedElements.forEach(el => {
// Ensure they have a base style for fading in if not already handled by CSS
// For now, we'll just observe them and let CSS handle .in-view if defined,
// or we can add a generic fade-in class.
// Given the specific request, let's focus on Lore Cards.
// But the previous code animated them, so let's keep basic fade-in for them.
el.classList.add('fade-in-scroll'); // We might need to add this class to CSS if we want generic fade
observer.observe(el);
});
});