禁止頁面滾動效果


應用場景:頁面出現浮層時禁止頁面滾動(移動端滑動)

1. pc端實現

$('body').css('overflow','hidden');//浮層出現時窗口不能滾動設置
$('body').css('overflow','auto');// 浮層關閉時滾動設置

2.移動端實現

var preHandler=function(e){e.preventDefault();},// 注意此處代碼片段必須這樣提出來已保證傳入下邊兩個事件的處理程序一樣才生效,分別寫到事件處理程序中不生效。
document.addEventListener('touchmove', me.preHandler,false);//阻止默認滑動事件
document.removeEventListener('touchmove', me.preHandler, false);//浮層關閉時解除事件處理程序

3.浮層實現效果

.mask{
    position: fixed;
    top:0;
    left:0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    z-index: 99;
}
.box-introduce-content{ // 浮層中內容上下左右居中實現
    position: absolute;
    margin: auto;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0 0.15rem;
    height: 4.23rem;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM