【问题标题】:iPhone Web App - Disable body scrolling but allow on all elements within bodyiPhone Web App - 禁用正文滚动但允许正文中的所有元素
【发布时间】:2012-12-03 13:33:52
【问题描述】:

我目前正在使用以下代码来禁用 html 和 body 的滚动:

document.ontouchmove = function(event){
    event.preventDefault();
}

这可行,但它会禁用页面内的所有本机滚动。我在这个网站上看到了很多关于此的主题,但我没有看到一个明确的答案或示例,它允许在页面内的任何其他元素上滚动而无需定义一个。

你能不能只禁用滚动的弹性,然后用-webkit-overflow滚动来滚动body?

如果有人知道这样做的有效方法,我将不胜感激。谢谢。

【问题讨论】:

    标签: javascript jquery css iphone-web-app


    【解决方案1】:

    最有效的方法是使用 css?

    html {
        overflow: hidden;
        height: 100%;
    }
    
    body {
        margin: 0;
        height: 100%;
        background-color: red;
    }
    .container {
        overflow-y: scroll;
        height: 100%;
        background-color: green;
    }
    

    http://jsfiddle.net/xBuhy/

    【讨论】:

      猜你喜欢
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 2014-08-15
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多