我目前正在开发一个针对触摸设备(主要是 iOS)进行优化的单页 Web 应用程序。我已经通过以下方式实现了新的 iOS 原生滚动-webkit-overflow-scrolling: touch;
一切运行良好,除了我们仍在整个页面主体上体验苹果弹性滚动效果。
这涉及到当滚动结束或主体被推动时整个页面从视口的顶部/底部移开,并且真正暴露了这是一个网络应用程序的事实。我已关注各种指导方针关于如何防止这种情况,当它们确实起作用时,它们会阻止内部可滚动元素一起工作。
这是一个小提琴展示我到目前为止所使用的。
有没有人找到一种解决方案,禁用身体弹性滚动,但让内部可滚动工作?
我已经采用了很好的解决方案有条件地阻止移动 Safari 中的滚动/触摸移动事件使用道场:
var initialY = null;
dojo.connect(document, 'ontouchstart', function(e) {
initialY = e.pageY;
});
dojo.connect(document, 'ontouchend', function(e) {
initialY = null;
});
dojo.connect(document, 'ontouchcancel', function(e) {
initialY = null;
});
dojo.connect(document, 'ontouchmove', function(e) {
if(initialY !== null) {
if(!dojo.query(e.target).closest('#content')[0]) {
// The element to be scrolled is not the content node
e.preventDefault();
return;
}
var direction = e.pageY - initialY;
var contentNode = dojo.byId('content');
if(direction > 0 && contentNode.scrollTop <= 0) {
// The user is scrolling up, and the element is already scrolled to top
e.preventDefault();
} else if(direction < 0 && contentNode.scrollTop >= contentNode.scrollHeight - contentNode.clientHeight) {
// The user is scrolling down, and the element is already scrolled to bottom
e.preventDefault();
}
}
});
在本例中,要滚动的元素是#content。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)