Skip to content

Instantly share code, notes, and snippets.

@pokorson
Created March 2, 2016 10:42
Show Gist options
  • Save pokorson/251b2931e39b3a973d5d to your computer and use it in GitHub Desktop.
Save pokorson/251b2931e39b3a973d5d to your computer and use it in GitHub Desktop.
JS Element in View
####### 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