Last active
January 21, 2019 05:27
-
-
Save AdarshKonchady/be620ac5b2fffa1b807164590bfdf98a to your computer and use it in GitHub Desktop.
isInViewport
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) { | |
var rect = element.getBoundingClientRect(); | |
var html = document.documentElement; | |
if ( | |
rect.top >= 0 && | |
rect.left >= 0 && | |
rect.bottom <= (window.innerHeight || html.clientHeight) && | |
rect.right <= (window.innerWidth || html.clientWidth) | |
) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment