jscrollpane block scrolling parent

馋奶兔 提交于 2019-12-05 08:39:13

The behaviour you describe is by design. This is how the native browser scrollbars behave on an element which has overflow: auto. I wouldn't recommend changing it. However, if you wish to then Borgenk's answer is correct, you can use this code:

$('.scroll-pane')
    .jScrollPane()
    .bind(
        'mousewheel',
        function(e)
        {
            e.preventDefault();
        }
    );

See an example here (you may need to shrink your window so the parent has any need to scroll): http://jsfiddle.net/VYcDZ/51/

You could use event.preventDefault()

$('.selector').mousewheel(function(event) {
    event.preventDefault();
});

Ran into this problem tonight... saw no one had the answer so i wrote it up

var blockScrollTarget;    
$('.jscroll').mousewheel(blockScroll);
        ......
    function blockScroll(e) {
        blockScrollTarget = blockScrollTarget || $(e.currentTarget);
        var d = blockScrollTarget.data('jsp');
        if(d.getPercentScrolledY() == 1 || d.getPercentScrolledY() == 0) {
          return true;
        }
        if(d.getIsScrollableV()) {
          e.preventDefault();
        }
      }

The above answers didn't work for me. If you are comfortable with editing the plugin source, you can expose the relevant internal methods to the public api:

// Public API
$.extend(
  jsp,
    {

      ...

      initMousewheel : function(){
        initMousewheel();
      },
      removeMousewheel : function(){
        removeMousewheel();
      }

    }
  );

Now you can conditionally and pragmatically eanable/disable the scrolling of any jscrollpane:

api = $('#full-page-container').data('jsp');
api.removeMousewheel(); // disable
api.initMousewheel(); // enable
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!