javascript實(shí)現(xiàn)蒙版與禁止頁面滾動
更新時間:2020年01月11日 10:10:57 作者:Original-Heart
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)蒙版與禁止頁面滾動,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了javascript實(shí)現(xiàn)蒙版與禁止頁面滾動的具體代碼,供大家參考,具體內(nèi)容如下
項目需求:頁面很長,要求加個蒙版,點(diǎn)擊特定位置蒙版消失可以滑動頁面,否則蒙版存在頁面不可以滑動;要同時兼容移動端和pc端。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name=viewport content="width=device-width,initial-scale=1,user-scalable=no">
<title>蒙版與禁止?jié)L動</title>
<style>
.container{
width:200px;
height:2000px;
background-color:blue;
}
.modal{
width: 100%;
position:fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 999;
background-color: rgba(0,0,0,0.7);
background-size: 100%;
}
.p{
font-size: 50px;
color:red;
text-align:center;
}
</style>
</head>
<body>
<div class="container">
<p>內(nèi)容</p>
</div>
<!-- 蒙版 -->
<div class="modal">
<p class="p">按鈕</p>
</div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(function(){
// 阻止蒙版后頁面滑動
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
//移動端
$(".modal").on('touchmove',function(e){
e.stopPropagation();
e.preventDefault();
$('.p').click(function(){
$(this).parent().hide();
})
})
} else {
//PC端
var flag=true;
$('.p').click(function(){
$(this).parent().hide();
$('body').css({ "overflow":'visible'});
flag=false;
})
if(flag)
$('body').css({ "overflow":'hidden' });
}
})
</script>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- JavaScript 獲取滾動條位置并將頁面滑動到錨點(diǎn)
- vue使用原生js實(shí)現(xiàn)滾動頁面跟蹤導(dǎo)航高亮的示例代碼
- js監(jiān)聽html頁面的上下滾動事件方法
- 通過 JS 判斷頁面是否有滾動條的實(shí)現(xiàn)方法
- Javascript實(shí)現(xiàn)頁面滾動時導(dǎo)航智能定位
- js/jquery控制頁面動態(tài)加載數(shù)據(jù) 滑動滾動條自動加載事件的方法
- js實(shí)現(xiàn)刷新頁面后回到記錄時滾動條的位置【兩種方案可選】
- js實(shí)現(xiàn)頁面刷新滾動條位置不變
- JavaScript 實(shí)現(xiàn)頁面滾動動畫
相關(guān)文章
訪問百度和谷歌網(wǎng)速測試的javascript代碼
訪問百度和谷歌網(wǎng)速測試的javascript代碼...2007-08-08
JavaScript實(shí)現(xiàn)簡單進(jìn)度條效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡單進(jìn)度條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-03-03
教你如何解密js/vbs/vbscript加密的編碼異處理小結(jié)
教你如何解密js/vbs/vbscript加密的編碼異處理加密代碼 是一篇非常不錯的加密解密原理,希望大家仔細(xì)研究2008-06-06

