Add detection for scroll is over

https://stackoverflow.com/a/51142522/10559526
This commit is contained in:
Daniel Schädler 2025-03-17 23:20:33 +01:00
parent 4edcfac209
commit 7837b40d56
1 changed files with 9 additions and 5 deletions

View File

@ -87,20 +87,24 @@ export function FavoriteBar({teams}) {
} }
}); });
} }
scrollTo.scrollIntoView({behavior: 'smooth', block: 'center'}); // Smoothly scroll to the target element
let scrollTimeout; let scrollTimeout;
// Add a scroll event listener to start the highlighting after scrolling only const handleScroll = () => {
window.addEventListener('scroll', function() {
clearTimeout(scrollTimeout); clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(function() { scrollTimeout = setTimeout(() => {
setIsPulsing(false); setIsPulsing(false);
scrollTo.classList.add('scroll-to-highlight'); scrollTo.classList.add('scroll-to-highlight');
setTimeout(() => { setTimeout(() => {
scrollTo.classList.remove('scroll-to-highlight'); scrollTo.classList.remove('scroll-to-highlight');
}, 2000); }, 2000);
window.removeEventListener('scroll', handleScroll);
}, 100); }, 100);
}, {once: true}); };
scrollTo.scrollIntoView({behavior: 'smooth', block: 'center'}); // Smoothly scroll to the target element
// Add a scroll event listener to start the highlighting after scrolling only
window.addEventListener('scroll', handleScroll);
}; };
if (isLoading) { if (isLoading) {