How to disable scrolling temporarily?

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

    Store scroll length in a global variable and restore it when needed!

    var sctollTop_length = 0;
    
    function scroll_pause(){
      sctollTop_length = $(window).scrollTop();
      $("body").css("overflow", "hidden");
    }
    
    function scroll_resume(){
      $("body").css("overflow", "auto");
      $(window).scrollTop(sctollTop_length);
    }
    

提交回复
热议问题