Skip to content

Commit

Permalink
better-animations
Browse files Browse the repository at this point in the history
  • Loading branch information
alurubalakarthikeya committed Aug 3, 2024
1 parent d57dc03 commit df6f194
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ document.addEventListener("DOMContentLoaded", function() {
threshold: 0.1 // Adjust this value as needed
};

const observerCallback = (entries, observer) => {
let debounceTimer;
const debounce = (callback, delay) => {
return (...args) => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => callback.apply(this, args), delay);
};
};

const observerCallback = debounce((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
if (entry.target.classList.contains('fade-in-up-target')) {
Expand All @@ -87,7 +95,7 @@ document.addEventListener("DOMContentLoaded", function() {
observer.unobserve(entry.target); // Optionally unobserve the element after the animation
}
});
};
}, 100); // Adjust the debounce delay as needed

const observer = new IntersectionObserver(observerCallback, observerOptions);

Expand Down

0 comments on commit df6f194

Please sign in to comment.