js實(shí)現(xiàn)彈框效果
本文實(shí)例為大家分享了js實(shí)現(xiàn)彈框效果的具體代碼,供大家參考,具體內(nèi)容如下
利用display來(lái)控制彈窗的現(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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂(lè)代碼2. 關(guān)于html嵌入xml數(shù)據(jù)島如何穿過(guò)樹(shù)形結(jié)構(gòu)關(guān)系的問(wèn)題3. 不要在HTML中濫用div4. 初試WAP之wml+ASP查詢5. WMLScript的語(yǔ)法基礎(chǔ)6. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)7. XML 非法字符(轉(zhuǎn)義字符)8. el-input無(wú)法輸入的問(wèn)題和表單驗(yàn)證失敗問(wèn)題解決9. XML入門的常見(jiàn)問(wèn)題(三)10. JSP取得在WEB.XML中定義的參數(shù)
