廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
創(chuàng)新互聯(lián)是專業(yè)的疊彩網(wǎng)站建設(shè)公司,疊彩接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行疊彩網(wǎng)站開發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
<!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" alt="" id="showcont"> </div> </body> </html>
以上所述是小編給大家介紹的jQuery點(diǎn)擊彈出層彈出模態(tài)框點(diǎn)擊模態(tài)框消失代碼分享,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
新聞名稱:jQuery點(diǎn)擊彈出層彈出模態(tài)框點(diǎn)擊模態(tài)框消失代碼分享
文章源于:http://aaarwkj.com/article22/pjdicc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、軟件開發(fā)、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、搜索引擎優(yōu)化
聲明:本網(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)