[英]-webkit-overflow-scrolling breaks absolute positioning
I am building a page that needs to have some elements which stick to the top of the page when they would otherwise be scrolled off the screen. 我正在构建一个页面,当它们以其他方式滚动离开屏幕时,需要有一些元素粘在页面顶部。 I managed to do this using
position:absolute
. 我设法使用
position:absolute
来做到这一点。 Everything was working perfectly, but it needed momentum scrolling. 一切都很完美,但它需要动力滚动。 I added
-webkit-overflow-scrolling: touch
to the css of the scrollable area. 我添加了
-webkit-overflow-scrolling: touch
到可滚动区域的css。 This broke everything. 这打破了一切。 My sticky elements with
position:absolute
are now just scrolling with the rest of the content. 我的粘性元素与
position:absolute
现在只是滚动其余的内容。
My question is this: 我的问题是:
Why does -webkit-overflow-scrolling: touch
affect absolute positioning, and is there a way around this? 为什么
-webkit-overflow-scrolling: touch
影响绝对定位,有没有解决方法?
UPDATE: I added an alert whenever a child element becomes "fixed" or "unfixed". 更新:每当子元素变为“固定”或“未固定”时,我都会添加警报。 The alerts continue to fire, so the styling is still being applied, it just isn't working.
警报继续触发,因此样式仍在应用,它只是不起作用。 This means that it's not a problem with keeping track of scroll position but rather a problem with the styling.
这意味着跟踪滚动位置不是问题,而是样式问题。
UPDATE: I tried using position: fixed
instead of position: absolute
and -webkit-overflow-scrolling
broke that too 更新:我尝试使用
position: fixed
而不是position: absolute
和-webkit-overflow-scrolling
破坏了它
UPDATE: After a lot of digging, I found references to this problem here and here . 更新:经过大量挖掘,我在这里和这里找到了对这个问题的引用。 However, the only proposed solution in both cases is to restructure the DOM so that the sticky elements are not in the scrollable area.
但是,两种情况下唯一提出的解决方案是重构DOM,以便粘性元素不在可滚动区域中。 This is a difficult thing to do in my case, and I would prefer not to have to.
在我的情况下,这是一件很难的事情,我宁愿不必这样做。 Have things progressed since ios5 or is that still the only option?
自ios5以来有没有进展或者仍然是唯一的选择?
On the last question - yes the issue is present in ios5. 关于最后一个问题 - 是的,ios5中存在问题。 Extracting the absolute positioning element outside of the scrollable area worked fine for me.
在可滚动区域之外提取绝对定位元素对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.