1. 程式人生 > >【CSS-04】移動端蒙層底部頁面禁止滑動

【CSS-04】移動端蒙層底部頁面禁止滑動

//用$代替document.querySelector,節省重複程式碼; var $=function(selector){ return document.querySelector(selector); }; //彈出框程式碼 function show_popwindow(){ //頁面載入時,彈出框是隱藏的,當點選彈出按鈕時,彈出框彈出 document.getElementById("live-detail-popwindow").style.display = "block"; //下面的兩句是為了防止底部頁面滑動。注:必須對html和body都設定overflow:hidden,移動端才能禁止滑動
$('html').setAttribute("style","overflow:hidden;height:100%;"); $('body').setAttribute("style","overflow:hidden;height:100%;"); // pop window 的margin top //裝置的總高度 var height_total= document.documentElement.clientHeight; //container的高度 var popheight=$('#pop_container').offsetHeight; //top的值=(總高度-container高度)/2
var margin_top = (height_total-popheight) / 2; $('#pop_container').style.top=margin_top+"px"; } //視窗關閉時,pop-window需要隱藏,且body和html的overflow還原; function window_close(){ document.getElementById("live-detail-popwindow").style.display = "none"; $('html').setAttribute("style","overflow:auto;"
); $('body').setAttribute("style","overflow:auto;"); } </sctipt>