Reputation: 2564
I have a button, when scroll bar is bigger than 600, it will show, if less it will hide.
I'm not sure where is the problem, it is not working.
var scrollTop = $(window).scrollTop();
if(scrollTop<600){$('#top').hide();}
else{$('#top').show();}
Upvotes: 0
Views: 69
Reputation: 3874
You need to bind the scroll()
event to the window, rather than checking the scroll position once.
Try something like this:
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
if(scrollTop < 600) {
$('#top').hide();
} else {
$('#top').show();
}
});
Upvotes: 5