Skip to content

Instantly share code, notes, and snippets.

@shepelevstas
Created April 7, 2022 10:47
Show Gist options
  • Save shepelevstas/a000035880f69dfca36206edcce0c95e to your computer and use it in GitHub Desktop.
Save shepelevstas/a000035880f69dfca36206edcce0c95e to your computer and use it in GitHub Desktop.
html element becomes visible
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