1. 程式人生 > >JS 禁用背景頁面滾動

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); }