0

I have a light box on my page. I would like to disable the following function when the light box is opened and enable it again when the light box is closed.

Here is the code for the function:

$.fn.fullpage.setMouseWheelScrolling = function (value){
        if(value){
            addMouseWheelHandler();
        }else{
            removeMouseWheelHandler();
        }
};

HTML for the light box:

<div>
    <a class="example_open" href="#example">View Popup</a>
</div> 
<div id="example" class="popup"> 
    <div class="content">abc</div> 
    <button class="example_close"></button> 
</div> 

I'm using this plugin for the light box

How can I disable / enable the function based on the light box being visible?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Umer Saeed
  • 11
  • 2
  • Include the html for your lightbox and which lightbox plugin you are using – dehrg Sep 03 '14 at 14:59
  • possible duplicate of [How to disable scrolling temporarily?](http://stackoverflow.com/questions/4770025/how-to-disable-scrolling-temporarily) – Edi G. Sep 03 '14 at 15:04
  • Here is the code: And the following plugin: http://www.jqueryscript.net/demo/Responsive-Accessible-jQuery-Modal-Plugin-Popup-Overlay/ – Umer Saeed Sep 03 '14 at 15:07
  • For next time, include that code and the plugin in the question itself. You can edit your question after you have posted it – dehrg Sep 03 '14 at 15:40
  • @dehrg Acknowledged. Thanks for the guideline brother. – Umer Saeed Sep 03 '14 at 17:35

3 Answers3

0

If you mean disabling scrolling for whole page so try this:

$('html, body').css({
    'overflow': 'hidden',
    'height': '100%'
})

And in order to restore to default state:

$('html, body').css({
    'overflow': 'auto',
    'height': 'auto'
})

Check JSFiddle Demo

Moshtaf
  • 4,833
  • 2
  • 24
  • 34
0

The plugin you are using has javascript events which you can tap into. You can use them to set a variable, and then check for that variable in your scrolling function.

$(document).ready(function() {

    var isOpen;

    $('#my_popup').popup({
       onopen: function() {
           isOpen = true;
       },
       onclose: function() {
           isOpen = false;
       }
    });

    $.fn.fullpage.setMouseWheelScrolling = function (value){
       if ( ! isOpen ) {
           if(value){
               addMouseWheelHandler();
           }else{
               removeMouseWheelHandler();
           }
       }
    };
});
dehrg
  • 1,721
  • 14
  • 17
0
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = [37, 38, 39, 40];

function preventDefault(e) {
  e = e || window.event;
  if (e.preventDefault)
      e.preventDefault();
  e.returnValue = false;  
}

function keydown(e) {
    for (var i = keys.length; i--;) {
        if (e.keyCode === keys[i]) {
            preventDefault(e);
            return;
        }
    }
}

function wheel(e) {
  preventDefault(e);
}

function disable_scroll() {
  if (window.addEventListener) {
      window.addEventListener('DOMMouseScroll', wheel, false);
  }
  window.onmousewheel = document.onmousewheel = wheel;
  document.onkeydown = keydown;
}

function enable_scroll() {
    if (window.removeEventListener) {
        window.removeEventListener('DOMMouseScroll', wheel, false);
    }
    window.onmousewheel = document.onmousewheel = document.onkeydown = null;  
}


you can check the demo also

http://jsbin.com/disable-scrolling/1