效果圖:

圖(1)初始圖

圖(2)點(diǎn)擊按鈕后
代碼如下:
<!DOCTYPE HTML><html> <head> <meta charset="UTF-8" /> <title></title> <style> #mask { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 999; background: #666; opacity: 0.5; filter: alpha(opacity=50)-moz-opacity: 0.5; display: none; } .popup { position: absolute; left: 50%; width: 600px; height: 200px; background: #fff; z-index: 1000; border: 1px solid #333; display: none; } .btn_close { position: absolute; top: 5px; right: 5px; } </style> </head> <body> <button class="btn_show">遮罩層</button> <div id="mask"></div> <div class="popup"> <button class="btn_close">x</button> </div> <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script> <script> $(function() { $('.btn_show').click(function() { $('#mask').css({ display: 'block', height: $(document).height() }) var $Popup = $('.popup'); $Popup.css({ left: ($('body').width() - $Popup.width()) / 2+ 'px', top: ($(window).height() - $Popup.height()) / 2 + $(window).scrollTop() + 'px', display: 'block' }) }) $('.btn_close').click(function() { $('#mask,.popup').css('display', 'none'); }) }) </script> </body></html>以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持武林網(wǎng)!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注