-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (23 loc) · 950 Bytes
/
script.js
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
// Toggle mobile menu
document.querySelector(".mobile-btn").addEventListener("click", function () {
document.querySelector(".menu").classList.toggle("active");
});
// Scroll-triggered animations
document.addEventListener("DOMContentLoaded", function () {
const animatedElements = document.querySelectorAll('.animate-fade-in, .animate-slide-in');
if (animatedElements.length === 0) {
console.warn("No animated elements found.");
return; // Exit if no animated elements exist
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible'); // Add visible class to trigger animation
observer.unobserve(entry.target); // Stop observing once animated
}
});
});
animatedElements.forEach(element => {
observer.observe(element); // Observe each animated element
});
});