0

I'm wanting to show two divs when the page has been scrolled, but once they've appeared not be hidden anymore. The following code works for showing the divs but once I scroll back to the top they hide.

$(window).scroll(function() {
    if ($(this).scrollTop() > 0) {
        $("#tip-2").show();
        $("#now-available").show();
    } else {
        $("#tip-2").hide();
        $("#now-available").hide();
    }
});
4

1 回答 1

1

How about...

var madeVis = false;

$(window).scroll(function() {
    if ($(this).scrollTop() > 0) {
        $("#tip-2").show();
        $("#now-available").show();
        madeVis = true;
    } else if (!madeVis) {
        $("#tip-2").hide();
        $("#now-available").hide();
    }
});
于 2012-05-18T00:32:40.193 回答