Mobile Safari - “touchend” event not firing when last touch is removed?

前端 未结 2 1863
慢半拍i
慢半拍i 2021-01-01 00:54

The \"gesture\" I\'m trying to capture is a tap when but only when an element (other or same) already has a touch on it. So, touch (1) presses the button down while touch (2

2条回答
  •  迷失自我
    2021-01-01 01:35

    I can help you with one problem, but I don't know why the "touchend" isn't firing when both fingers leave the screen, when I run your code above, the "touchend" fires when either finger leaves the screen (on an iPhone 4)

    1) While the "touchend" javascript event for iPhone does have the "touches" property, it's always going to be empty when the last finger leaves the screen, because "touches" for the iPhone represents fingers currently touching the screen, and "touchend" only fires after a finger leaves the screen. So on "touchend" "e.touches.length" will always be 0 when the last finger is lifted.

    2) You can access which touches have changed in the "touchend" event by using the "changedTouches" property. This is problematic because it's behaviour is not very consistent.

    If you touch the screen with one finger, then another, and then you remove one finger, a number of things could happen.

    If you when you have removed the second finger, nothing has changed about the first finger, your event object in "touchend" will have "touches.length = 1" (the finger still on the screen) and "changedTouches.length = 1" (the finger that left the screen).

    However, if you are moving the first finger (even a bit) when you remove the second finger, then on "touchend" your event object will have "touches.length = 1" (the finger still on the screen) and "changedTouches.length = 2" (the finger that left the screen + the movement of the first finger).

    I found this article very helpful:

    http://m14i.wordpress.com/2009/10/25/javascript-touch-and-gesture-events-iphone-and-android/

提交回复
热议问题