0

I am trying to achieve this, when the user is scrolling-disable one element. When the user is not scrolling, revert the element to original state.

It is not a problem to make the first requirement, I don't know how to reverse it to previous state. Here is the code for doing something while the user is scrolling:

$(window).scroll(function(){
             $('#box').css('display','none');
         });

I tried with if-else statements, but I haven't got it to work. Here is the fiddle to see it on hand:

http://jsfiddle.net/y7ekd/

fluxus
  • 559
  • 5
  • 15
  • 29

2 Answers2

1

You can make it work with a little trick (timeout trick)

As scrolling is not a continuous event, it fires many times while you are scrolling

var timeout;  
$(window).scroll(function(){
       clearTimeout(timeout);
       $('#box').css('display','none');
       timeout = setTimeout(function(){
           $('#box').css('display','block');
       },200);
});

Demo ----> http://jsfiddle.net/y7ekd/1/

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0

Throttle it with a timeout, the scroll event fires many, many times so it has to be throttled to avoid flickering.

$(window).on('scroll', function(){
     $('#box').hide();

     clearTimeout($(this).data('timer'));

     $(this).data('timer', setTimeout(function() {
          $('#box').show();             
     }, 300));
});
adeneo
  • 312,895
  • 29
  • 395
  • 388