Rich
Rich

Reputation: 1156

Scrolling to show div elements

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();
    }
});

Upvotes: 0

Views: 650

Answers (1)

Snixtor
Snixtor

Reputation: 4297

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();
    }
});

Upvotes: 1

Related Questions