How to disable scrolling temporarily?

前端 未结 30 2466
萌比男神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:25

    Building on Cheyenne Forbes' answer, and one I found here via fcalderan: Just disable scroll not hide it? and to fix Hallodom's issue of the scrollbar disappearing

    CSS:

    .preventscroll{
        position: fixed;
        overflow-y:scroll;
    }
    

    JS:

    whatever.onclick = function(){
        $('body').addClass('preventscroll');
    }
    whatevertoclose.onclick = function(){
        $('body').removeClass('preventscroll');
    }
    

    This code does jump you to the top of the page, but I think that fcalderan's code has a workaround.

提交回复
热议问题