禁用iOS弹性体滚动和保持本机滚动正常工作
我目前正在开发一个针对触摸设备(主要是 iOS)进行优化的单页 Web 应用程序。我已经通过 -webkit-overflow-scrolling: touch;
实现了新的 iOS 原生滚动,一切运行良好,除了我们仍在整个页面主体上体验苹果弹性滚动效果。
这涉及到当滚动结束或主体被推动时整个页面从视口的顶部/底部移开,并且真正暴露了这是一个网络应用程序的事实。我遵循了关于如何防止这种情况的各种指南,虽然它们确实有效,但它们阻止了内部可滚动元素一起工作。
这是一个小提琴来演示我到目前为止所使用的内容。
有没有人找到一种解决方案,禁用身体弹性滚动,但让内部可滚动工作?
I am currently working on a single page web app optimized for touch devices, mainly iOS. I've implemented the new iOS native scrolling via -webkit-overflow-scrolling: touch;
and all works well except that we are still experiencing the apple elastic scroll effect on the whole page body.
This involves the whole page moving off the top/bottom of the viewport when a scroll ends or the body is pushed and really gives away the fact that this is a web app. I have followed various guidelines on how to prevent this and while they do work, they prevent inner scrollable elements from working altogether.
Here's a fiddle to demonstrate what I'm using so far.
Has anyone found a solution that disables body elastic scrolling but lets inner scrollables work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经采用了 Conditionally blockscrolling/touchmove event in mobile safari using Dojo 的良好解决方案:
要滚动的元素是 #content在这种情况下。
I've adapted the good solution from Conditionally block scrolling/touchmove event in mobile safari using Dojo:
The element to be scrolled is #content in this case.
也许 iScroll 就是您正在寻找的(如果我的问题正确的话)
Maybe iScroll is what you're looking for (if I got your question right)
冒着重复我的帖子的风险,我尝试解决同样的问题,到目前为止仅此而已:
如果您有一个未覆盖整个屏幕的溢出元素(例如在 iPad 应用程序中),则此方法有效。但如果您有移动应用程序并且整个视口都被溢出的元素覆盖,则它不起作用。
我唯一能想到的就是检查$('.scrollable')的scrollTop(),然后有条件地绑定preventDefault()(如果它是0)。
尝试后,我注意到webkit UA报告scrollTop总是为0即使元素执行本机溢出滚动的“内部弹跳”,也会滚动到顶部。所以我不能做任何事情,因为我需要一个负的滚动顶部来设置我的条件。
叹。令人沮丧。
At the risk of duplicating my post, I try to solve the same issue and so far am only this far:
This works if you have an overflow element that doesn't cover the whole screen, like in an iPad app for example. but it doesn't work if you have a mobile app and the entire viewport is covered by your overflowed element.
The only thing I could think of is to check the scrollTop() of the $('.scrollable') and then conditionally bind the preventDefault() if it's 0.
After trying, I noticed that the webkit UA reports scrollTop always as 0 when the element is scrolled to the top even when it does the "inside bounce" of the native overflow scroll. So i can't do anything since I'd require a negative scrollTop to set my condition.
Sigh. Frustrating.