jQuery实现简单弹窗遮罩效果
效果图:
图(1)初始图
图(2)点击按钮后
代码如下:
<!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>
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17