Skip to content

Instantly share code, notes, and snippets.

@seyedi
Created August 10, 2020 14:50
Show Gist options
  • Save seyedi/d376917201d59093c7c0c417a7cf1ed9 to your computer and use it in GitHub Desktop.
Save seyedi/d376917201d59093c7c0c417a7cf1ed9 to your computer and use it in GitHub Desktop.
inViewport Vanilla JS w/ IntersectionObserver
function inViewport(elem, callback, options = {}) {
return new IntersectionObserver(entries => {
entries.forEach(entry => callback(entry));
}, options).observe(document.querySelector(elem));
}
inViewport('.target', element => {
//element.isIntersecting (bool) true/false
}, {
root: document.querySelector('.scroll')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment