遮罩鼠标滑轮滚动无效

2017-09-12  本文已影响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};   
      }
  </script>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读