How to disable scrolling temporarily?

前端 未结 30 3318
萌比男神i
萌比男神i 2020-11-21 05:16

I\'m using the scrollTo jQuery plugin and would like to know if it is somehow possible to temporarily disable scrolling on the window element through Javascript? The reason

30条回答
  •  不要未来只要你来
    2020-11-21 05:32

    I know this is an old question, but I had to do something very similar, and after some time looking for an answer and trying different approaches, I ended up using a very easy solution.

    My problem was very similar, almost identical, the only difference is I didn't have to actually show the scroll bar - I just had to make sure its width would still be used, so the page's width would not change while my overlay was displayed.

    When I start sliding my overlay into the screen, I do:

    $('body').addClass('stop-scrolling').css('margin-right', 8);
    

    and after I slide my overlay off the screen I do:

    $('body').removeClass('stop-scrolling').css('margin-right', 0);
    

    IMPORTANT: this works perfectly because my overlay is positioned absolute, right: 0px when visible.

提交回复
热议问题