I'm trying to figure out how to check if a DOM element is visible within the windows viewport during scroll, I've been using many approaches and many plugins and I'm getting nowhere. Looks like when I attach viewport checkes to window.scroll it just doesn't work:
$(window).scroll(function() {
if(checkIfXInViewport) {
// this is getting executed ALL THE TIME
} else {
// this never happens even if X is NOT in viewport }
}
});
Here's an example using: http://jsfiddle.net/tuT7U/ (using https://github.com/zeusdeux/isInViewport/ ). Run the console, it always returns "visible" even if header is out of the viewport.... Why?
What am I doing wrong?