1

For performance reasons I want to deactivate a hover effect during scrolling and activate it again on scroll end. I'm using a class to activate and deactivate the hover.

Right now I have this

$(window).scroll(function(){
  scrolling = true;
  element.removeClass('hover');

  setTimeout(function() {
    if(!scrolling){
      element.addClass('hover');
    }
  }, 200);

  scrolling = false;
});

It applies a timeout of 200ms which checks if any other scroll events fired after this scroll. However, the timeout gets registered for every scroll event and fires multiple times after the scrolling ended.

I'm basically looking for a neat solution for this.

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
johnny
  • 8,696
  • 6
  • 25
  • 36
  • Your basic idea is spot on. The [answer here](http://stackoverflow.com/questions/9144560/jquery-scroll-detect-when-user-stops-scrolling) might be helpful in sorting out your timeout code. – Spudley May 24 '13 at 16:37

0 Answers0