Created
May 19, 2014 13:48
-
-
Save lmartins/aef730ca112409329a7d to your computer and use it in GitHub Desktop.
Check if an element is in Viewport
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
| isInViewport = (el) -> | |
| rect = el.getBoundingClientRect() | |
| html = document.documentElement | |
| return( | |
| rect.top >= 0 and | |
| rect.left >= 0 and | |
| rect.bottom <= (window.innerHeight or html.clientHeight) and | |
| rect.right <= (window.innerWidth or html.clientWidth) | |
| ) | |
| isInViewport(btnEl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment