Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to use jQuery to capture mouse scrolling Reply To: How to use jQuery to capture mouse scrolling

#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.

http://codepen.io/anon/pen/FBkLI