美文网首页
遮罩层禁止底层滚动条滚动

遮罩层禁止底层滚动条滚动

作者: 我就是心虚 | 来源:发表于2017-10-06 15:27 被阅读0次
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>遮罩层禁止底层滚动条滚动</title>
  <style>
      *{
        margin: 0;
        padding: 0;
      }
      ul,li{
        list-style:none;
      }
      li{
        width: 800px;
        height: 500px;
        background:red;
        margin-top:10px;
      }
      #btn{
        position: fixed;
        top:500px;
        right:200px;
      }
      #shade{
        position: fixed;
        top:0;
        bottom:0;
        left:0;
        right:0;
        background:rgba(0, 0, 0, .5);
        display: none;
      }
  </style>
</head>
<body>
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
  <button id="btn">遮罩层</button>
  <div id="shade"></div>

  <script>
      var btn=document.getElementById("btn");
      var shade=document.getElementById("shade");
      btn.onclick = function(){
        shade.style.display = "block";
        // window.onmousewheel=function(){return false};
        function disabledMouseWheel() {
          if (document.addEventListener) {
            document.addEventListener('DOMMouseScroll', scrollFunc, false);
          }
          window.onmousewheel = document.onmousewheel = scrollFunc;
        }
        function scrollFunc(e) {
           e = e || window.event;
            if(e.preventDefault) {
              e.preventDefault();
              e.stopPropagation();
            } else {
              e.cancelBubble=true;
              e.returnValue = false;
           }
           return false;
        }
        disabledMouseWheel();
      }

  </script>
</body>
</html>

相关文章

网友评论

      本文标题:遮罩层禁止底层滚动条滚动

      本文链接:https://www.haomeiwen.com/subject/fhqryxtx.html