js如何实现弹窗暗层效果
更新:HHH   时间:2023-1-8


这篇文章给大家分享的是有关js如何实现弹窗暗层效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="utf-8">
 <title></title>
 <link rel="stylesheet" href="http://r01.uzaicdn.com/content/v1/styles/subject.css"> 
 <link rel="stylesheet" href="styles/lianxi.css">
 <script src="https://cache.tdyun.com/upload/information/20200622/114/78000.png');</script><![endif]-->
 <style type='text/css'>
 .fn-mask{width: 100%;height: 100%;background: #000;opacity: 0.5;position: fixed;left: 0;top: 0;transition:all 0.5s ease 0s;z-index: 998;}
  button{margin:0 auto;display: block;margin-top: 300px;background: pink;}
  .main{width: 100px;height: 100px;background: #fff;position: fixed;left: 50%;top: 50%;z-index: 1000;text-align: center;line-height: 100px;}
  .main i{color: red;font-size: 36px;position: absolute;top:-30px;right: 0;cursor: pointer;}
 </style>
</head>
<body>
 <div class="box">
  <button>活动细则</button>
  <div class="fn-mask hide"></div>
  <div class="main hide">
  你好,我是弹窗
  <i>x</i>
  </div>
 </div>
</body>
 <script>
 $(function(){
 $('button').on('click',function(){
 $('.fn-mask').removeClass('hide');
 $('.main').removeClass('hide');
 })
 $('.main i').on('click',function(){
 $('.fn-mask').addClass('hide');
 $('.main').addClass('hide');
 })
})
 </script>
</html>

感谢各位的阅读!关于“js如何实现弹窗暗层效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

返回web开发教程...