Created
August 10, 2020 14:50
-
-
Save seyedi/d376917201d59093c7c0c417a7cf1ed9 to your computer and use it in GitHub Desktop.
inViewport Vanilla JS w/ IntersectionObserver
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 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