Reputation: 1156
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
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