本文介绍了在javascript中强制停止动力在iphone / ipad上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在javascript中强制停止iphone / ipad上的动量滚动?

Is it possible to force-stop momentum scrolling on iphone/ipad in javascript?

额外:非常确定这是天空中的馅饼,但是对于奖励点(荣誉和荣誉),在dom-manipulation和scrollTo应用之后,以相同的动量恢复滚动在强制停止之前。怎么样?

Extra: pretty sure this is pie in the sky, but for bonuspoints (honor and kudos), after dom-manipulation and a scrollTo applied, resume scroll with the same momentum before the forced stop. How to?

推荐答案

使用。 lib移除移动设备上的300ms点击延迟,并在惯性/动量滚动期间启用事件捕获。

This is actually very possible when using fastclick.js. The lib removes the 300ms click delay on mobile devices and enables event capturing during inertia/momentum scrolling.

包括fastclick并将其附加到body元素后,我的代码停止滚动并转到顶部看起来像这样:

After including fastclick and attaching it to the body element, my code to stop scrolling and go to the top looks like this:

scrollElement.style.overflow = 'hidden';
scrollElement.scrollTop = 0;
setTimeout(function() {
  scrollElement.style.overflow = '';
}, 10);

诀窍是设置 overflow:hidden ,停止惯性/动量滚动。请参阅我的小提琴,了解的全面实施。

The trick is to set overflow: hidden, which stops the inertia/momentum scrolling. Please see my fiddle for a full implementation of stop scrolling during inertia/momentum.

这篇关于在javascript中强制停止动力在iphone / ipad上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:36