-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
193 lines (166 loc) · 6 KB
/
script.js
File metadata and controls
193 lines (166 loc) · 6 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
// Smooth scrolling for navigation links
document.addEventListener('DOMContentLoaded', function() {
// Navigation functionality
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetSection = document.querySelector(targetId);
if (targetSection) {
targetSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Active navigation highlighting
function updateActiveNav() {
const sections = document.querySelectorAll('.section');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop - 200) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + current) {
link.classList.add('active');
}
});
}
// Scroll to top button
const scrollToTopBtn = document.createElement('button');
scrollToTopBtn.innerHTML = '↑';
scrollToTopBtn.className = 'scroll-to-top';
scrollToTopBtn.setAttribute('aria-label', 'Scroll to top');
document.body.appendChild(scrollToTopBtn);
scrollToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Show/hide scroll to top button
function toggleScrollToTop() {
if (window.pageYOffset > 300) {
scrollToTopBtn.classList.add('visible');
} else {
scrollToTopBtn.classList.remove('visible');
}
}
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate');
}
});
}, observerOptions);
// Observe elements for animation
const animateElements = document.querySelectorAll('.topic-card, .format-card, .audience-list li');
animateElements.forEach(el => {
observer.observe(el);
});
// Staggered animation for topic cards
const topicCards = document.querySelectorAll('.topic-card');
topicCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 0.1}s`;
});
// Staggered animation for audience list items
const audienceItems = document.querySelectorAll('.audience-list li');
audienceItems.forEach((item, index) => {
item.style.transitionDelay = `${index * 0.1}s`;
});
// Staggered animation for format cards
const formatCards = document.querySelectorAll('.format-card');
formatCards.forEach((card, index) => {
card.style.transitionDelay = `${index * 0.2}s`;
});
// Event listeners
window.addEventListener('scroll', function() {
updateActiveNav();
toggleScrollToTop();
});
// Initial calls
updateActiveNav();
toggleScrollToTop();
// Add loading animation
document.body.style.opacity = '0';
document.body.style.transition = 'opacity 0.5s ease-in-out';
window.addEventListener('load', function() {
document.body.style.opacity = '1';
});
// Add hover effects for cards
const cards = document.querySelectorAll('.content-card, .topic-card, .format-card');
cards.forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-8px)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0)';
});
});
// Add click effects for navigation
navLinks.forEach(link => {
link.addEventListener('click', function() {
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = 'scale(1)';
}, 150);
});
});
// Keyboard navigation support
document.addEventListener('keydown', function(e) {
if (e.key === 'Home') {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
} else if (e.key === 'End') {
e.preventDefault();
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}
});
// Add focus management for accessibility
const focusableElements = document.querySelectorAll('a, button, [tabindex]:not([tabindex="-1"])');
focusableElements.forEach(element => {
element.addEventListener('focus', function() {
this.style.outline = '2px solid #1e3a8a';
this.style.outlineOffset = '2px';
});
element.addEventListener('blur', function() {
this.style.outline = 'none';
});
});
});
// Add performance optimization
if ('requestIdleCallback' in window) {
requestIdleCallback(function() {
// Preload critical resources
const criticalImages = document.querySelectorAll('img[data-src]');
criticalImages.forEach(img => {
img.src = img.dataset.src;
});
});
}
// Add error handling
window.addEventListener('error', function(e) {
console.error('An error occurred:', e.error);
});
// Add resize handler for responsive adjustments
let resizeTimer;
window.addEventListener('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Recalculate positions after resize
updateActiveNav();
}, 250);
});