Created
September 21, 2023 07:47
-
-
Save rubinchyk/adb87613aa067e17ac4d77b3ec6dd587 to your computer and use it in GitHub Desktop.
[Intersection Observer - After scroll to block - do something] Intersection Observer - After scroll to block - do something
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const observer = new IntersectionObserver(handleIntersection, { threshold: 0 }); | |
function handleIntersection(entries, observer) { | |
entries.forEach(entry => { | |
if (entry.isIntersecting) { | |
entry.target.style.backgroundColor = "#e74c3c"; | |
} else { | |
entry.target.style.backgroundColor = "#3498db"; | |
} | |
}); | |
} | |
const wrappers = document.querySelectorAll(".wrapper"); | |
wrappers.forEach((entry) => { observer.observe(entry) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment