How to return mousewheel scroll event when unbind is not working

Currently I am working with a site that have a Chart on the middle which is scroll able to zoom-in and zoom-out using mouse scroll but my problem is when i scroll the page overflow or whole body is also scrolling i have tried this block of code the binding for stop scrolling it is working on the chart but i cannot unbind or return it back to the original when i am scrolling outside the Chart. Below is the code that i am using. I have also tried to changing the function to return true and still not working.

BindScroll

      $('body').bind('mousewheel DOMMouseScroll', lockScroll);

unbind scroll

      $('body').unbind('mousewheel DOMMouseScroll', lockScroll);


      function lockScroll(e) {
           e.preventDefault();
      }

1 answer

  • answered 2018-04-17 04:06 Uttam Kukadiya

    Instand of unbinding, just ignore the mouse wheel event.

    var mindingMousewheel = true
    

    set it to false when you don’t want to watch it. And test it before you do anything.

    $('body').bind('mousewheel', function(event, delta) {
              if (! mindingMousewheel) return;
    })