Created
December 27, 2020 12:57
-
-
Save MuhammadKhizar7/7b3bf5f5c238c51f8709fd2d0a8158e3 to your computer and use it in GitHub Desktop.
It check if element in viewport or not
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 isInViewPort(element) { | |
// Get the bounding client rectangle position in the viewport | |
const bounding = element.getBoundingClientRect(); | |
// Checking part. Here the code checks if it's *fully* visible | |
// Edit this part if you just want a partial visibility | |
return bounding.top >= 0 && | |
bounding.left >= 0 && | |
bounding.right <= (window.innerWidth || document.documentElement.clientWidth) && | |
bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment