程序停止-webkit溢出滚动 [英] Programatically halt -webkit-overflow-scrolling

查看:100
本文介绍了程序停止-webkit溢出滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个phonegap应用程序,使用iOS本机滚动通过 -webkit-overflow-scrolling 在div。我想要能够手动停止正在进行的滚动,当用户单击按钮(滚动回到页面的顶部)。

I have a phonegap application that uses iOS native scrolling through -webkit-overflow-scrolling in a div. I want to be able to manually halt an ongoing scroll when the user clicks a button (to scroll back to the top of the page). Is this doable?

推荐答案

这实际上是非常有可能的,当使用 fastclick.js

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.

在包含快速点击并将其附加到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.

这篇关于程序停止-webkit溢出滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆