Skip to content

Instantly share code, notes, and snippets.

@amycheng
Created Aug 22, 2013
Embed
What would you like to do?
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