Created
February 6, 2014 08:30
-
-
Save snowman-repos/8840302 to your computer and use it in GitHub Desktop.
Determine if an 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
# Determine if an element is in the visible viewport | |
isInViewport = (element) -> | |
rect = element.getBoundingClientRect() | |
html = document.documentElement | |
rect.top >= 0 and rect.left >= 0 and rect.bottom <= (window.innerHeight or html.clientHeight) and rect.right <= (window.innerWidth or html.clientWidth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment