您好,欢迎访问一九零五行业门户网

如何使用JS弹出DIV并使整个页面背景变暗

这次给大家带来如何使用js弹出div并使整个页面背景变暗,使用js弹出div并使整个页面背景变暗的注意事项有哪些,下面就是实战案例,一起来看一下。
1.首先写一个遮罩层p,然后再写一个弹窗的p
<!-- 遮罩层 --> <p id="cover" style="background: #000; position: absolute; left: 0px; top: 0px; width: 100%; filter: alpha(opacity=30); opacity: 0.3; display: none; z-index: 2 ">    </p> <!-- 弹窗 --> <p id="showp" style="width: 80%; margin: 0 auto; height: 9.5rem; border: 1px solid #999; display: none; position: absolute; top: 40%; left: 10%; z-index: 3; background: #fff">   <!-- 标题 -->   <p style="background: #f8f7f7; width: 100%; height: 2rem; font-size: 0.65rem; line-height: 2rem; border: 1px solid #999; text-align: center;" >     提示   </p>   <!-- 内容 -->   <p style="text-indent: 50px; height: 4rem; font-size: 0.5rem; padding: 0.5rem; line-height: 1rem; ">     js弹窗 js弹出p,并使整个页面背景变暗</p>   <!-- 按钮 -->   <p style="background: #418bca; width: 80%; margin: 0 auto; height: 1.5rem; line-height: 1.5rem; text-align: center;color: #fff;margin-top: 1rem; -moz-border-radius: .128rem; -webkit-border-radius: .128rem; border-radius: .128rem;font-size: .59733rem;" onclick="closewindow()">     确 定   </p> </p>
js代码:(把jq引进来)
<script type="text/javascript">   // 弹窗   function showwindow() {     $('#showp').show();  //显示弹窗     $('#cover').css('display','block'); //显示遮罩层     $('#cover').css('height',document.body.clientheight+'px'); //设置遮罩层的高度为当前页面高度   }   // 关闭弹窗   function closewindow() {     $('#showp').hide();  //隐藏弹窗     $('#cover').css('display','none');   //显示遮罩层   } </script>
效果:
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
怎样使用js调用模式与this关键字绑定
怎样操作angularjs使用filter自定义过滤器控制ng-repeat去重
以上就是如何使用js弹出div并使整个页面背景变暗的详细内容。
其它类似信息

推荐信息