-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (25 loc) · 808 Bytes
/
script.js
File metadata and controls
28 lines (25 loc) · 808 Bytes
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
// Throttle function for better performance
function throttle(func, delay) {
let lastCall = 0;
return function(...args) {
const now = Date.now();
if (now - lastCall >= delay) {
lastCall = now;
func.apply(this, args);
}
};
}
// Simple scroll fade-in with throttling
const handleScroll = throttle(() => {
const sections = document.querySelectorAll('section');
const windowHeight = window.innerHeight;
sections.forEach(section => {
const rect = section.getBoundingClientRect();
if(rect.top < windowHeight - 50) {
section.classList.add('visible');
}
});
}, 100);
window.addEventListener('scroll', handleScroll, { passive: true });
// Trigger on load to handle initial viewport
handleScroll();