How to disable scrolling temporarily?

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

    var winX = null, winY = null;
    window.addEventListener('scroll', function () {
        if (winX !== null && winY !== null) {
            window.scrollTo(winX, winY);
        }
    });
    function disableWindowScroll() {
        winX = window.scrollX;
        winY = window.scrollY;
    };
    function enableWindowScroll() {
        winX = null;
        winY = null;
    };
    

提交回复
热议问题