Home › Forums › JavaScript › How to use jQuery to capture mouse scrolling › Reply To: How to use jQuery to capture mouse scrolling
October 3, 2013 at 8:11 am
#151958
nkrisc
Participant
Here’s something I whipped together that seems to accomplish what you want. There might be a better way so if there is, hopefully someone else can help with that.
$(document).scroll(function(){
if($(document).scrollTop() <= 1){
$('body').css('background','red'); //what happens when you leave top
}
if($(document).scrollTop() === 0){
$('body').css('background','green'); //what happens when you're back at top
}
});
Just know that the event for when you’re back at the top won’t trigger on page load is it only check if you’re at the top while scrolling.