js實(shí)現(xiàn)彈框效果
本文實(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;}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. UDDI FAQs2. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲3. ASP基礎(chǔ)入門第三篇(ASP腳本基礎(chǔ))4. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容5. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法6. html清除浮動的6種方法示例7. JSP之表單提交get和post的區(qū)別詳解及實(shí)例8. css進(jìn)階學(xué)習(xí) 選擇符9. ASP.NET Core實(shí)現(xiàn)中間件的幾種方式10. asp.net core項(xiàng)目授權(quán)流程詳解
