[英]iOS: -webkit-overflow-scrolling:touch and scrollTop
I have some trouble when trying to back to the top of a list. 尝试返回列表顶部时遇到一些麻烦。
I put -webkit-overflow-scrolling:touch
on the list to get momentum scroll. 我将
-webkit-overflow-scrolling:touch
放在列表上以获取动量滚动。 However when I'm using jQuery scrollTop();
但是,当我使用jQuery
scrollTop();
while the momentum scroll is still going, it jumps to the top but it doesn't stop the momentum. 尽管动量滚动仍在进行,但它会跳到顶部,但不会停止动量。 So it keeps going down again until the momentum ends.
因此它继续下降直到动量结束。
Is there an easy way to stop momentum scroll? 有一种简单的方法可以阻止动量滚动吗?
Set your list's -webkit-overflow-scrolling
style to 'auto'
and then back to 'touch'
after a short timeout. 将列表的
-webkit-overflow-scrolling
样式设置为'auto'
,然后在短暂的超时后恢复为'touch'
。
ie 即
let scrollContainer = document.getElementById('yourListId');
scrollContainer.style['-webkit-overflow-scrolling'] = 'auto'; // stop scroll
setTimeout(function() {
scrollContainer.scrollTop = 0; // or jQuery scrollTop()
scrollContainer.style['-webkit-overflow-scrolling'] = 'touch'; // re-enable
}, 2);
Reference: this SO answer . 参考: 此SO答案 。 (modified their implementation to get rid of scrollbar redraw jerkiness on desktop browsers)
(修改了其实现,以消除滚动条在桌面浏览器上的重绘问题)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.