Found this SO great question/answer re extending jQuery to determine if an element is off screen:
How to check if an element is off-screen
Also found this article, but could not use to resolve problem:
http://code.tutsplus.com/tutorials/dissecting-jquery-filters--net-13954
Using scurker's (accepted answer) code, this should alert (and hide element) when yellow DIV scrolls off screen. It doesn't. Cannot find the problem.
jsFiddle (for those who prefer)
Raw jQuery / CSS / HTML Code (S.O. Embedded):
jQuery.expr.filters.offscreen = function(el) {
return (
(el.offsetLeft + el.offsetWidth) < 0
|| (el.offsetTop + el.offsetHeight) < 0
|| (el.offsetLeft > window.innerWidth || el.offsetTop > window.innerHeight)
);
};
var d1=0,d2=0,d3=0,dir='dn',cpos=0,lpos=0;
var div1=$('#d1'),div4=$('#d4'),div5=$('#d5');
$(window).scroll(function() {
cpos = $(window).scrollTop(); //get current scroll position
div4.html(cpos);
dir = (cpos>lpos) ? 'dn': 'up'; //get scroll direction
//div5.html(dir);
if (dir=='dn'){
d1 = cpos + (cpos*1.25);
}else{
d1 = cpos - (cpos*1.25);
}
div1.html(d1); //update pos numbers
div1.dequeue().stop().animate({'top':d1+'px'});
lpos = cpos; //store for line 6
div1.is(':offscreen').hide();
div5.html( (div1.is(':offscreen')) ? 'yup':'no' );
});
html{height:1800px;}
body{background: url('http://placekitten.com/g/500/500') no-repeat center center fixed;background-size:cover;}
.divs{position:fixed;top:0;height:120px;width:60px;}
#d1{background:yellow;}
#d4{background:wheat;left:380px;}
#d5{background:white;left:440px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id="d1" class="divs"></div>
<div id="d4" class="divs"></div><!-- curr window scrollTop -->
<div id="d5" class="divs"></div><!-- curr scroll direction -->