This is a small Javascript function which tells you whether an HTML element is currently visible - that is, whether or not it's been scrolled out of view on the page.
This function requires jQuery.
function isScrolledIntoView(elem) { | |
var docViewTop = $(window).scrollTop(); | |
var docViewBottom = docViewTop + $(window).height(); | |
var elemTop = $(elem).offset().top; | |
var elemBottom = elemTop + $(elem).height(); | |
return ( (elemBottom >= docViewTop) && (elemTop <= docViewBottom) && (elemBottom <= docViewBottom) && (elemTop >= docViewTop) ); | |
} |