Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/56b47c2658a244b75cc4 to your computer and use it in GitHub Desktop.
Save andreasvirkus/56b47c2658a244b75cc4 to your computer and use it in GitHub Desktop.
// Meant to find out if a DOM element is scrolled into view
// aka if it is visible on the screen.
function appear(elem) {
var $elem = $(elem);
var $window = $(window);
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment