Is there a way to check whether the div
is entirely visible to the user? I mean the scroll bar is positioned so that the entire div
fits inside the viewport.
Is there a way to check whether the div
is entirely visible to the user? I mean the scroll bar is positioned so that the entire div
fits inside the viewport.
2 Answers
Reset to default 8This is exactly what this was created for: http://www.appelsiini/projects/viewport
You need to check positions for the scrollbar and the div in question, and pare them in the scroll
event handler:
$(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/mblase75/dMwMb/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745368533a4624693.html
评论列表(0条)