How to programmatically disable page scrolling with jQuery

后端 未结 23 2110
滥情空心
滥情空心 2020-11-22 08:09

Using jQuery, I would like to disable scrolling of the body:

My idea is to:

  1. Set body{ overflow: hidden;}
  2. Capture the current
23条回答
  •  心在旅途
    2020-11-22 08:25

    This may or may not work for your purposes, but you can extend jScrollPane to fire other functionality before it does its scrolling. I've only just tested this a little bit, but I can confirm that you can jump in and prevent the scrolling entirely. All I did was:

    • Download the demo zip: http://github.com/vitch/jScrollPane/archives/master
    • Open the "Events" demo (events.html)
    • Edit it to use the non-minified script source:
    • Within jquery.jscrollpane.js, insert a "return;" at line 666 (auspicious line number! but in case your version differs slightly, this is the first line of the positionDragY(destY, animate) function

    Fire up events.html, and you'll see a normally scrolling box which due to your coding intervention won't scroll.

    You can control the entire browser's scrollbars this way (see fullpage_scroll.html).

    So, presumably the next step is to add a call to some other function that goes off and does your anchoring magic, then decides whether to continue with the scroll or not. You've also got API calls to set scrollTop and scrollLeft.

    If you want more help, post where you get up to!

    Hope this has helped.

提交回复
热议问题