Created
March 2, 2016 10:42
-
-
Save pokorson/251b2931e39b3a973d5d to your computer and use it in GitHub Desktop.
JS Element in View
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 takes jQuery object as argument | |
####### currently working only for one element | |
var isInView = function($element){ | |
elementOffsetTop = $element.offset().top; | |
elementHeight = $element.outerHeight(); | |
windowTop = document.body.scrollTop; | |
windowHeight = window.innerHeight; | |
if( elementOffsetTop < (windowTop + windowHeight) | |
&& (elementOffsetTop + elementHeight) > windowTop) | |
return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment