zoukankan      html  css  js  c++  java
  • js开启和关闭页面滚动【亲测有效】

    在移动端的页面开发过程中,经常会遇到点击弹框禁止页面滚动的情景,下面就来说下具体的做法。。。

    第一步:构建一个函数

    function bodyScroll(event){
      event.preventDefault();
    }

    第二步:点击禁止页面滚动

    $(".button").click(function(){
        document.body.addEventListener('touchmove',bodyScroll,false);
        $('body').css({'position':'fixed',"width":"100%"});
    });

    第三步:点击开启页面滚动

    $(".shadow-closes").click(function(){
        document.body.removeEventListener('touchmove',bodyScroll,false);
        $("body").css({"position":"initial","height":"auto"});
    });

    完整代码:

    $(".button").click(function(){
        document.body.addEventListener('touchmove',bodyScroll,false);
        $('body').css({'position':'fixed',"width":"100%"});
    });
    $(".shadow-closes").click(function(){
        document.body.removeEventListener('touchmove',bodyScroll,false);
        $("body").css({"position":"initial","height":"auto"});
    });
    function bodyScroll(event){
      event.preventDefault();
    }

  • 相关阅读:
    Java——GUI
    linux变量
    shell脚本
    linux查找文件命令
    composer的安装
    restful的nginx配置方法
    api调用安全
    PHP设置Cookie的HTTPONLY属性
    php的异常处理
    php错误报告
  • 原文地址:https://www.cnblogs.com/e0yu/p/11792585.html
Copyright © 2011-2022 走看看