Skip to content

Instantly share code, notes, and snippets.

@donohoe
Created July 20, 2012 12:37
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 donohoe/3150507 to your computer and use it in GitHub Desktop.
Save donohoe/3150507 to your computer and use it in GitHub Desktop.
Check if an element in DOM is in viewable area
/* Requires jQuery */
function isInView(el) {
var docViewTop = $(window).scrollTop();
var docViewBtm = docViewTop + $(window).height();
var elTop = $(el).offset().top;
var elBtm = elTop + $(el).height();
return ((elBtm <= docViewBtm) && (elTop >= docViewTop));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment