Check if full div is available to user

Is there a way to check if the divuser is fully displayed ? I mean, the scroll bar is positioned so that everything divfits inside the viewport.

+5
source share
2 answers

This is exactly what was created for: http://www.appelsiini.net/projects/viewport

+8
source

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/

+2
source

All Articles