Answer the question
In order to leave comments, you need to log in
How do we make an object (let's say a menu) appear when we've scrolled down about 500px?
And vice versa: when we move up, the element disappears.
Answer the question
In order to leave comments, you need to log in
.menu { display: none; }
$(window).on('scroll', function() {
if ($(this).scrollTop() > 500) {
$('.menu').fadeIn();
} else {
$('.menu').fadeOut();
}
});
var ttl = 0;
var prevS, prevScrollDir;
$(window).on('scroll', function() {
var s = $(this).scrollTop();
var scrollDir = s > prevS;
if (scrollDir == prevScrollDir) {
ttl += (s-prevS);
if (ttl > 500) {
$(".m").removeClass('hide');
}
} else {
ttl = 0;
$(".m").addClass('hide');
}
prevS = s;
prevScrollDir = scrollDir;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question