js實(shí)現(xiàn)彈框效果
更新時(shí)間:2021年03月18日 17:22:05 作者:程序猿余某人
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)彈框效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了js實(shí)現(xiàn)彈框效果的具體代碼,供大家參考,具體內(nèi)容如下
利用display來控制彈窗的現(xiàn)實(shí)和隱藏
<!-- 彈出層 --> <div id="popLayer"></div> <!--黑色蒙版 --> <div id="popBox"> <div class="close"> X </div> <div> <!-- 內(nèi)容 --> </div> </div>
js:
//點(diǎn)擊關(guān)閉按鈕
var close = document.querySelector(".close")
close.onclick = function () {
console.log("點(diǎn)擊")
var popBox = document.getElementById("popBox");
var popLayer = document.getElementById("popLayer");
popBox.style.display = "none";
popLayer.style.display = "none";
}
//需要顯示時(shí)調(diào)用
var popLayer = document.getElementById("popLayer");
popBox.style.display = "block";
popLayer.style.display = "block";
CSS:
/* 彈出層 */
#popLayer {
display: none;
background-color: #000;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 10;
opacity: 0.6;
}
/*彈出層*/
#popBox {
display: none;
background-color: #FFFFFF;
z-index: 11;
width: 220px;
height: 300px;
position: fixed;
top: 0;
right: 0;
left: 0;
bottom: 0;
margin: auto;
}
/*關(guān)閉按鈕*/
#popBox .close {
width: 20px;
height: 20px;
border-radius: 50%;
position: absolute;
border: 1px solid #fff;
color: #fff;
text-align: center;
line-height: 20px;
right: 8px;
top: 8px;
z-index: 50;
}
#popBox .close a {
text-decoration: none;
color: #2D2C3B;
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- vue.js中toast用法及使用toast彈框的實(shí)例代碼
- vue.js實(shí)現(xiàn)只彈一次彈框
- js+html5實(shí)現(xiàn)半透明遮罩層彈框效果
- js自定義彈框插件的封裝
- 基于layer.js實(shí)現(xiàn)收貨地址彈框選擇然后返回相應(yīng)的地址信息
- js實(shí)現(xiàn)上下左右彈框劃出效果
- struts json 類型異常返回到j(luò)s彈框問題解決辦法
- javascript實(shí)現(xiàn)無法關(guān)閉的彈框
- 輕松實(shí)現(xiàn)js彈框顯示選項(xiàng)
- Bootstrap和Angularjs配合自制彈框的實(shí)例代碼
相關(guān)文章
微信小程序配置視圖層數(shù)據(jù)綁定相關(guān)示例
這篇文章主要為大家介紹了微信小程序配置視圖層數(shù)據(jù)綁定相關(guān)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪<BR>2022-04-04
javascript實(shí)現(xiàn)tab切換的四種方法
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)tab切換的四種方法,并且對(duì)每個(gè)方法進(jìn)行了評(píng)價(jià),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-11-11

