Created
October 27, 2019 16:45
-
-
Save 0000marcell/9cdc15d7b38a90b271e310e64c4c1442 to your computer and use it in GitHub Desktop.
any part of the element is in the viewport
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
function isAnyPartOfElementInViewport(el) { | |
const rect = el.getBoundingClientRect(); | |
const windowHeight = (window.innerHeight || document.documentElement.clientHeight); | |
const windowWidth = (window.innerWidth || document.documentElement.clientWidth); | |
const vertInView = (rect.top <= windowHeight) && ((rect.top + rect.height) >= 0); | |
const horInView = (rect.left <= windowWidth) && ((rect.left + rect.width) >= 0); | |
return (vertInView && horInView); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment