廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
<!DOCTYPE html> <html> <head> <title>jQuery彈出層 模態(tài)框</title> <script src="./jquery.min.js" type="text/javascript"></script> <style> .btn{ height:100px; } .black_over{ display: none; position: fixed; width: 100%; height: 100%; background-color: black; z-index:1001; top: 0; left: 0; right: 0; left: 0; margin: auto; background-color: rgba(0,0,0,0.8); } .white_content { display: none; position: fixed; z-index:1002; overflow: auto; } </style> <script type="text/javascript"> $(function () { //彈出隱藏層 function ShowDiv(show_div,bg_div){ document.getElementById(show_div).style.display='block'; document.getElementById(bg_div).style.display='block' ; var _windowHeight = $(window).height(),//獲取當(dāng)前窗口高度 _windowWidth = $(window).width(),//獲取當(dāng)前窗口寬度 _popupHeight = $("#"+show_div).height(),//獲取彈出層高度 _popupWeight = $("#"+show_div).width();//獲取彈出層寬度 _posiTop = (_windowHeight - _popupHeight)/2; _posiLeft = (_windowWidth - _popupWeight)/2; $("#"+show_div).css({"left": _posiLeft + "px","top":_posiTop + "px","display":"block"});//設(shè)置position }; //關(guān)閉彈出層 function CloseDiv(show_div,bg_div) { document.getElementById(show_div).style.display='none'; document.getElementById(bg_div).style.display='none'; }; $(".btn").click(function () { var src = $(this).attr("src"); $("#showcont").attr("src",src); ShowDiv('MyDiv','fade') }); $("#fade").click(function () { CloseDiv('MyDiv','fade') }); }); </script> </head> <body> <!--<input id="Button1" type="button" value="點(diǎn)擊彈出層" onclick="ShowDiv('MyDiv','fade')" />--> <!--圖片請(qǐng)換成自己的,點(diǎn)擊圖片彈出--> <img src="tu.png" alt="sd" class="btn" > <img src="pic.jpg" alt="sd" class="btn" > <!--彈出層時(shí)背景層DIV--> <div id="fade" class="black_over"> </div> <!--彈出層的內(nèi)容--> <div id="MyDiv" class="white_content"> <img src="tu.png" id="showcont"> </div> </body> </html>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站jinyejixie.com,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前標(biāo)題:jQuery點(diǎn)擊彈出層彈出模態(tài)框點(diǎn)擊模態(tài)框消失代碼分享-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)鏈接:http://jinyejixie.com/article34/djcipe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、App開(kāi)發(fā)、定制開(kāi)發(fā)、網(wǎng)站營(yíng)銷、企業(yè)網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容