You need to check the positions for the scroll bar and the corresponding div and compare them in the event handler scroll:
$(window).scroll(function() {
var top = $(window).scrollTop();
var bottom = top + $(window).height();
var dtop = $('#mydiv').position().top;
var dbottom = dtop + $('#mydiv').height();
if (dtop>=top && dbottom<=bottom) {
alert('okay!');
}
});
http://jsfiddle.net/mblase75/dMwMb/
source
share