Created
February 18, 2016 05:59
-
-
Save jwelshiv/19cdb5b5921344f5d9ef to your computer and use it in GitHub Desktop.
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 isElementVisible (el, withinEl) { | |
var withinRect = withinEl ? | |
withinEl.getBoundingClientRect() : | |
{ top: 0, left: 0, right: window.innerWidth, bottom: window.innerHeight }; | |
var rect = el.getBoundingClientRect(); | |
return ( | |
rect.top >= withinRect.top && | |
rect.left >= withinRect.left && | |
rect.bottom <= withinRect.bottom && | |
rect.right <= withinRect.right | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Determine if one element is visible within the other