在Mobile Safari中有没有办法使用TouchEndInside? [英] Is there a way to TouchEndInside in Mobile Safari?

查看:98
本文介绍了在Mobile Safari中有没有办法使用TouchEndInside?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定用户是否在iPhone网络应用的移动版Safari中进行了touchupinside。到目前为止,我一直没有成功。无论触摸事件发生在屏幕上的哪个位置,touchend事件都会触发,我似乎无法辨别目标在事件参数中的任何变化。

I'm trying to determine whether a users does a touchupinside in mobile safari for an iPhone web app. So far I've been unsuccessful. touchend event fires regardless of where the touchup event happens on the screen, and I can't seem to discern that the target has changed by anything in the event argument.

可以有人指出我如何使用javascript捕获touchendinside(与touchendoutside)事件的正确方向?

Can anyone point me in the right direction on how to capture a touchendinside (vs. touchendoutside) event using javascript?

$('a.arrow').bind('touchend',function(e) {
        console.log($(e.srcElement)); //both of these always return the same element
        console.log($(e.toElement)); //both of these always return the same element
    });


推荐答案

我找到了一篇文章 Google发布了一篇文章,说明了如何检测内部与外部的联络。基本技巧是:

I found an article Google published indicating how to detect whether a touchend is inside versus outside. The basic trick is:


  • 有3个处理程序:一个在touchstart,touchmove和touchend上。
  • Have 3 handlers: one on touchstart, touchmove, and touchend.

  1. touchstart:保存触摸的(x,y)坐标

  2. touchmove:检查触摸是否没有移动任意一个轴上的像素数,如果是这样,请停止跟踪触摸。

  3. touchend:如果你仍在跟踪它,它就是在里面;如果没有,它就是在外面。


你可以随时变得更复杂通过使用实际目标的边界等,但对于大多数可能足够的应用程序。

You can always get more complex by using the actual target's bounds, etc., but for most applications that is probably sufficient.

这篇关于在Mobile Safari中有没有办法使用TouchEndInside?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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