JavaScript蒙板(model)功能的簡(jiǎn)單實(shí)現(xiàn)代碼
思路:
•創(chuàng)建一個(gè)蒙板, 設(shè)置蒙板的堆疊順序保證能將其它元素蓋住
position: absolute;
top: 0;
left: 0;
display: none;
background-color: rgba(9, 9, 9, 0.63);
width: 100%;
height: 100%;
z-index: 1000; •設(shè)置蒙板中內(nèi)容的背景色和展示格式
width: 50%;
text-align: center;
background: #ffffff;
border-radius: 6px;
margin: 100px auto;
line-height: 30px;
z-index: 10001; •綁定事件, 動(dòng)態(tài)切換蒙板的 display 屬性
function showModel() {
document.getElementById('myModel').style.display = 'block';
}
function closeModel() {
document.getElementById('myModel').style.display = 'none';
}
注意事項(xiàng): 蒙板要采用絕對(duì)定位, 寬和高要占満整個(gè)頁(yè)面, 堆疊順序要大
源代碼
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>蒙板</title>
<style>
.container {
width: 900px;
margin: 50px auto;
text-align: center;
}
#myModel {
position: absolute;
top: 0;
left: 0;
display: none;
background-color: rgba(9, 9, 9, 0.63);
width: 100%;
height: 100%;
z-index: 1000;
}
.model-content {
width: 50%;
text-align: center;
background: #ffffff;
border-radius: 6px;
margin: 100px auto;
line-height: 30px;
z-index: 10001;
}
</style>
</head>
<body>
<div class="container">
<button onclick="showModel()">彈出蒙板</button>
<div id="myModel" onclick="closeModel()">
<div class="model-content">
<p>你好啊,我是內(nèi)容~~</p>
<p>
<button id="closeModel" onclick="closeModel()">關(guān)閉</button>
</p>
</div>
</div>
</div>
<script>
function showModel() {
document.getElementById('myModel').style.display = 'block';
}
function closeModel() {
document.getElementById('myModel').style.display = 'none';
}
</script>
</body>
</html>
以上所述是小編給大家介紹的JavaScript蒙板(model)功能的簡(jiǎn)單實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- AngularJs 彈出模態(tài)框(model)
- angularjs自定義ng-model標(biāo)簽的屬性
- angularjs在ng-repeat中使用ng-model遇到的問(wèn)題
- Django中模型Model添加JSON類(lèi)型字段的方法
- [JSF]使用DataModel處理表行事件的實(shí)例代碼
- JavaScript中的View-Model使用介紹
- js實(shí)現(xiàn)在頁(yè)面上彈出蒙板技巧簡(jiǎn)單實(shí)用
- javascript 窗口加載蒙板 內(nèi)嵌網(wǎng)頁(yè)內(nèi)容
- javascript創(chuàng)建頁(yè)面蒙板的一些知識(shí)技巧總結(jié)
相關(guān)文章
firefox下對(duì)ajax的onreadystatechange的支持情況分析
firefox下對(duì)ajax的onreadystatechange的支持分析。用的到的朋友可以參考下。2009-12-12
JavaScript編寫(xiě)簡(jiǎn)單的計(jì)算器
這篇文章主要介紹了JavaScript如何編寫(xiě)簡(jiǎn)單的計(jì)算器,功能很簡(jiǎn)單,可以實(shí)現(xiàn)加減乘除功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-11-11
js中點(diǎn)擊空白區(qū)域時(shí)文本框與隱藏層的顯示與影藏問(wèn)題
文本框獲得焦點(diǎn)的時(shí)在文本框的下方顯示一個(gè)浮動(dòng)層,點(diǎn)擊文本框隱藏浮動(dòng)層,下面為大家介紹下鼠標(biāo)點(diǎn)擊時(shí)文本框與隱藏層處理問(wèn)題,感興趣的朋友可以參考下2013-08-08
Javascript Bootstrap的網(wǎng)格系統(tǒng),導(dǎo)航欄和輪播詳解
這篇文章主要為大家介紹了Javascript Bootstrap的網(wǎng)格系統(tǒng),導(dǎo)航欄和輪播,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2021-11-11

