touchmove后Touchend不触发 [英] Touchend not firing after touchmove

查看:668
本文介绍了touchmove后Touchend不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个网页,移动设备检测 scrollTop的位置,滚动到页面的顶部,如果 scrollTop的是超过一半的文件高度低于或滚动至底部,如果它不是。

I'm trying to make a page for mobile devices that detects the scrollTop position and scrolls to the top of the page if scrollTop is lower than half the document height or scroll to bottom if its not.

我已经实现了,通过使用这样的:

I have achieved that by using this:

var ScrollTimeout;
$(window).on('scroll',function(){
    clearTimeout(ScrollTimeout);
    ScrollTimeout = setTimeout(scrollToTopOrBottom,200);
    });

的问题是,在超时的火灾时,用户停止滚动,但仍然有在屏幕上的手指

The problem is that the timeout fires when the user has stopped scrolling but still has the finger on the screen.

然后,我曾与 touchend 的事件,这是伟大的。

Then I worked with the touchend event and it was great.

$(document).on('touchend',function(){
    scrollToTop();
    });

用户可以停止滚动(用手指仍然在屏幕上),然后继续滚动而不触发 scrollToTopOrBottom()的功能。

The user could stopped scrolling (with the finger still on the screen) and then continue scrolling without triggering the scrollToTopOrBottom() function.

现在的问题是,该事件是浏览器之间的incosistent:

The problem is, that event is incosistent between browsers:

在某些浏览器傲游(Maxthon和Android),在 touchend 活动取得预计的效果,但在Opera Mobile和Chrome浏览器中, touchend 事件不会触发。对此的解释是,<一个href="http://stackoverflow.com/questions/7691551/touchend-event-in-ios-webkit-not-firing"><$c$c>touchend不火,因为 touchcancel 前。已被解雇

In some browsers (Maxthon and Android), the touchend event worked as intended but in Opera Mobile and Chrome, the touchend event doesn't fires. The explanation for this is that touchend doesn't fires because touchcancel has been fired before.

我已经试过这种

$(document).on('touchmove',function(e){
    e.preventDefault();
    });

和成功地避免了触发 touchcancel 的,但不幸也避免滚动的自然行为。

and succesfully avoided the triggering of touchcancel, but unluckily also avoided the natural behaviour of scrolling.

有谁知道如何才能实现这一目标?我完全没了主意。

Does anyone know how can this be achieved? I'm completely out of ideas.

感谢。

推荐答案

试图附加监听两个touchend和touchcancel。

try to attach listener on both touchend and touchcancel.

$(document).on('touchend touchcancel', function() {
    doSomthing();
});

这篇关于touchmove后Touchend不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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