iOS7 position:fixed; works ugly

陌路散爱 提交于 2019-12-05 16:31:24

I had the same problem. I had a fixed element over the body and this was very buggy. And for me height:auto; instead of height:100% worked. Full code:

body,
html{
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:auto; /* iOS position:fixed; elements fix (not 100%) */
    min-height:100%;
    overflow-x:hidden;
}

position:fixed on iOS 7 works pretty well, actually (there are minor issues, for instance juddering might be an issue depending on certain factors) so I think maybe you're trying to mimic a sticky scroll (where an element fixes when scrolling to a certain y-offset).

Unfortunately, for iOS you can't do this easily (when you scroll, or flick, all JavaScript is halted, which is why position:fixed happens at the end of the event. If you're lucky, you could hope the user pans and position:fixed on touchmove...)

As you mentioned, there are workarounds where you apply overflow and mimic native scroll (iScroll, for instance). These work, but they're memory intensive (thank you, hardware acceleration for smooth scrolling) so performance could be an issue depending on your need.

For iOS 7, there's a value for position, which is sticky. This works really well, as demonstrated here:

http://html5-demos.appspot.com/static/css/sticky.html
http://caniuse.com/css-sticky

The only drawback is that it's limited to iOS 6.1 and 7. However, if older devices are not a concern, position:sticky is a great workaround since it's native solution.

Just try to make your blocks with inner scroll (overflow-y: scroll) and place them like inline-blocks near each other. So as a result you'll get independent scrollable content.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!