【问题标题】:Stop body scrolling in Mobile Safari在 Mobile Safari 中停止正文滚动
【发布时间】:2014-01-04 08:53:48
【问题描述】:

我试图在模式叠加层打开时阻止页面主体滚动(完全)。

模态框覆盖整个屏幕({position: fixed;top:0;left:0;right:0;bottom:0;}),并且有自己的滚动功能。但是,当我在模态窗口上运行到滚动结束时,主窗口开始在它后面滚动。我已经尝试了所有我能想到的让身体停止滚动的方法。这些事情没有奏效:

CSS

body {
    overflow: hidden;
    pointer-events: none;
    -webkit-overflow-scrolling: none;
}
#content { /* which contains all the non-modal content of the body */
    -webkit-transform: scale(0);
    position: relative; left: 100%;
}
  • 使用 iScroll
  • 阻止窗口或正文的滚动事件
  • 阻止 body 上的 touchstart 事件

【问题讨论】:

    标签: css scroll mobile-safari


    【解决方案1】:

    看起来你已经很接近了。

    当你的模式打开时,试试这个 CSS:

    body{
        overflow:visible;
        max-height:100%; /* or 100px or something smaller than the screen if your viewport isn't set */
        height:100% /* or 100px or something smaller than the screen */
    }
    

    【讨论】:

    • 很遗憾,没有。仍然不会阻止正文滚动。
    • Hmm.. 您是否尝试过将#content 显示模式切换为绝对高度:当 Modal 启动时为 0?我担心如果#content 不再对页面滚动高度有贡献,这可能会导致内容“跳跃”,但可能会起作用。
    • 是的,这确实会停止滚动,但这也意味着当#content 的高度恢复到初始值时,滚动位置会丢失。
    • 在#content处于临时状态时“缓存”滚动位置怎么样 - 当模式关闭时,只需拉动 data-scroll 属性(或任何你称之为的属性)并设置 body ScrollTop到那个值?
    • 是的,我自己刚刚找到了这个解决方案。真是一团糟。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-21
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多