JS 禁用背景页面滚动

var s_top=0;
    // 禁止滚动
    function bodyScroll(event){  
        event.preventDefault();  
    }

    //禁止背景页面滚动
    function unScroll(){
        s_top = $(window).scrollTop();
        document.body.addEventListener('touchmove',bodyScroll,false);  
        $('body').css({'position':'fixed',"width":"100%"});
    }

    // 恢复背景页面滚动
    function scroll(){
        document.body.removeEventListener('touchmove',bodyScroll,false);   
        $("body").css({"position":"initial","height":"auto"});
        $(window).scrollTop(s_top);
    }

猜你喜欢

转载自blog.csdn.net/afgasdg/article/details/82494754