弹层 蒙层 阻止 出现滚动

这篇文章描述了一个关于网页弹窗的实现方法,当弹窗显示时阻止页面滚动,弹窗关闭后恢复页面滚动。使用jQuery来处理弹窗的显示和关闭事件,并通过修改`document.body`和`document.documentElement`的overflow属性控制滚动条的状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

弹窗后 页面不滚动

 /* 投票弹窗 */
      .pop,
      .pop1 {
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        top: 0;
        left: 0;
        position: fixed;
        display: none;
        z-index: 11;
      }

      .pop-box {
        width: 480px;
        height: 328px;
        background: #ffffff;
        border-radius: 8px;
        position: fixed;
        top: 50%;
        left: 50%;
        margin-top: -164px;
        margin-left: -240px;
        box-sizing: border-box;
        position: relative;
        padding: 27px 30px 24px 30px;
      }
 <div class="pop">
     <div class="pop-box">
		//这里面写内容
	</div>
 </div>
<script>
 // 关闭投票弹窗
    $(document).on("click", ".close", function (e) {
      e.stopPropagation();  //防止冒泡
      $(this).parent().parent().parent().css("display", "none");
      //恢复body滚动
      document.body.style.overflow = "";
      //恢复整个网页滚动
      document.documentElement.style.overflow = "";
    });
    // 打开投票弹窗
    $(document).on("click", ".place", function (e) {
      e.stopPropagation(); //防止冒泡
      $(".pop").css("display", "block");
      // 打开蒙层时禁止后面的主题有滚动
      //禁止body滚动
      document.body.style.overflow = "hidden";
      //禁止整个网页滚动
      document.documentElement.style.overflow = "hidden";
    });
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值