zoukankan      html  css  js  c++  java
  • 禁止屏幕滚动

    <!DOCTYPE> 
    <html> 
    <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
      <meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0" />
      <style>
        *{
          margin: 0;
          padding:0;
      }
      button{
          margin: 10px;
      }
      .test{
          position: relative;
          width: 300px;
          height: 1000px;
          background: #ccc;
      }
      .test .head,
      .test .center,
      .test .foot{
          position: absolute;
          left:0;
      }
      .test .head{
          top:0;
      }
      .test .center{
          top: 500px;
      }
      .test .foot{
          bottom: 0;
      }
    </style>
    </head> 
    <body> 
      <button type="button" id="no_scroll">点我屏幕不能滚动</button>
      <button type="button" id="scroll">点我屏幕允许滚动</button>
      <div class="test">
        <p class="head">这里是头部</p>
        <p class="center">这里是中部</p>
        <p class="foot">这里是底部</p>
    </div>
    <script type="text/javascript">
        var handler = function () {
            event.preventDefault();
            event.stopPropagation();
        }; 
        document.getElementById("no_scroll").addEventListener('click',function(){
            document.body.style.cssText="overflow:hidden";
            document.body.addEventListener('touchmove',handler,false);
            document.body.addEventListener('wheel',handler,false);
        });
        document.getElementById("scroll").addEventListener('click',function(){
            document.body.style.cssText="overflow:auto";
            document.body.removeEventListener('touchmove',handler,false);
            document.body.removeEventListener('wheel',handler,false);
        });
    </script>
    </body> 
    </html> 
  • 相关阅读:
    设计模式享元模式实现C++
    并查集
    设计模式代理模式实现C++
    设计模式装饰模式实现C++
    最小生成树Prim算法实现
    图的邻接矩阵存储
    威佐夫博弈(Wythoff Game)初识 HDU 1527 POJ 1067
    设计模式原型模式实现C++
    三种经典博弈问题 BashGame;WythoffGame;NimmGame;
    设计模式外观模式实现C++
  • 原文地址:https://www.cnblogs.com/theWayToAce/p/7079201.html
Copyright © 2011-2022 走看看