Skip to content

Instantly share code, notes, and snippets.

@amycheng
Created August 22, 2013 21:10
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 amycheng/6312825 to your computer and use it in GitHub Desktop.
Save amycheng/6312825 to your computer and use it in GitHub Desktop.
a javascript function to check if a html element is in view
function inView(el){
//check if a DOM element is in view
var scrollDistance=document.body.scrollTop;
if (scrollDistance>=el.offsetTop&&scrollDistance<el.offsetHeight+el.offsetTop) {
return true;
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment