Mobile Safari: inertia scrolling on body AND minimal UI behavior?

こ雲淡風輕ζ 提交于 2019-12-21 17:04:06

问题


This question requires some explaining, so please bear with me.

Contrary to popular belief, inertia scrolling (the very smooth 60fps scrolling) is not enabled on web pages in Mobile Safari by default. As it makes a world of difference in user experience, I have enabled it by dynamically applying this CSS to the HTML and BODY element of the page, after a Modernizr test for iOS specifically:

<style>
.touchscroll {
 overflow: auto;
 -webkit-overflow-scrolling: touch;
 position:relative;
 height:100%;
}

.touchscroll body { 
 height:100%;
 overflow: auto;
 -webkit-overflow-scrolling: touch;
 position:relative;
}
</style>

The above basically makes the body element a scrollable element and by means of -webkit-overflow-scrolling: touch, one gets the smooth intertia scrolling effect on the entire page. Some more background on this solution can be found here (disclaimer: article by myself).

It works, so far, so good. The problem is that this solution effectively disables another highly desired behavior of Mobile Safari: normally, when scrolling down, it will make the address bar smaller, and hide the bottom bar of the browser entirely. They re-appear when scrolling back up.

Unfortunately, the above technique disables this for some reason. Yes, we've got super smooth scrolling, yet the browser bar is always large and the bottom bar permanently stays visible, both taking up valuable space.

My question therefore is, can I have both? I want the super smooth scrolling on the entire page, yet I also want the default hiding behavior of browser elements when scrolling.

An example of a site where I am using this is here: http://www.jungledragon.com/

If you open that in Mobile Safari, you will see the smooth scrolling, yet not the hiding of browser elements when scrolling down.


回答1:


I think you're setting both the <html> and the <body> element to scroll. You should apply these CSS rules to 1 element you want to be able to scroll.

So either the html or body, not both.



来源:https://stackoverflow.com/questions/34494124/mobile-safari-inertia-scrolling-on-body-and-minimal-ui-behavior

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