views:

28

answers:

1

Using Javascript, Jquery preferably, I want to be able to trigger the visiblity of the div when a user is at a certain page height. NYtimes has an example of this when you scroll to the bottom of a story, a slider pops out with another news story, and goes away if you scroll up.

+1  A: 

I think the methods you want are:

$(document).scroll()    // event triggered whenever the page is scrolled
$(document).height()    // gets the height of the entire page
$(window).height()      // gets the height of the current window
$(document).scrollTop() // gets the top position currently visible

Using these, you could write a method to show a div when the window is 100 pixels from the bottom:

$(document).scroll(function() {
    var scrollBottom = $(document).scrollTop() + $(window).height();
    var height = $(document).height();
    if (scrollBottom > height - 100)
        $("div").show();
    else
        $("div").hide();
});
David Fullerton
looks good i will try it!
james