Created
April 7, 2022 10:47
-
-
Save shepelevstas/a000035880f69dfca36206edcce0c95e to your computer and use it in GitHub Desktop.
html element becomes visible
This file contains hidden or 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
function onVisible(el, once=true) { | |
return new Promise((done, fail) => { | |
new IntersectionObserver((entries, observer) => { | |
entries.forEach(entry => { | |
if (entry.intersectionRatio > 0) { | |
done(el, observer, entry) | |
if (once) {observer.disconnect()} | |
} | |
}) | |
}).observe(el) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment