zoukankan      html  css  js  c++  java
  • 移动端禁止页面滚动

    移动端遮罩层出现后,底部的页面还是可以滚动的,用下面的方法可以禁止滚动,但是解除禁止后滚动条会回到顶部。如果想滚动条保持在遮罩层出现时的位置,可以根据实际开发配合scrollIntoView()来使用。

    /**
     * 移动端禁止页面滚动
     * 
     * @returns {object} 
     */
    function stopScroll(){
        var html=document.getElementsByTagName('html')[0];
        var body=document.getElementsByTagName('body')[0];
        var o={};
        o.can=function(){
            html.style.overflow="visible";
            html.style.height="auto";
            body.style.overflow="visible";
            body.style.height="auto";
        },
        o.stop=function(){
            html.style.overflow="hidden";
            html.style.height="100%";
            body.style.overflow="hidden";
            body.style.height="100%";
        }
        return o
    }

    var scroll=stopScroll()
    scroll.stop() //禁止页面滚动
    scroll.can() //接触禁止
  • 相关阅读:
    Windbg DUMP
    NET媒体文件操作组件TagLib
    NET Framework、.NET Core、Xamarin
    面向切面编程
    微服务
    NET Core
    Yeoman generator
    Service Fabric
    Vue.JS 2.x
    CoreCLR
  • 原文地址:https://www.cnblogs.com/haqiao/p/8512547.html
Copyright © 2011-2022 走看看