Closed rjgotten closed 12 years ago
So it should use originalEvent.changedTouches
? The only way I could test touch features was using the iOS and Android emulators in Browserstack - which is probably not the most real-life situation.
You should use changedTouches
, yes. For 'touchend' events the Touch
instance corresponding to the finger that was removed from the touch surface will only be present in the changedTouches
list. It will not be present in touches
(which represents all active touches on the screen) or targetTouches
(which filters touches
down to those that started on the event's target
element). If you need further reference, there are examples and more information available in the Touch Events CR from the W3C: http://www.w3.org/TR/touch-events/
I find that Chrome's mouse-based touch event emulation provides a good balance between debugging and real-life representation for testing features of single-touch. Click the small gear in the bottom right of the developer tools to go to the options screen and toggle the feature there. Multi-touch is going to be hard to test without an actual touch device.
Btw. To be compatible with multi-touch devices you'll also need to fix the drag, drop and swipe handling. You need to keep track of the unique value of the identifier
property that started the interaction sequence in the 'touchstart' event and use that to retrieve information on the correct touch point in corresponding 'touchmove' and 'touchend' events. You cannot simply assume that the first index in a TouchList is the correct, same touch point every time.
(Also it will be kind of interesting to know the jQuery++ project's stance on msPointer for Internet Explorer 10, which is going to be yet another set of input events to work with...)
The
$.Event.prototype.vector
method tries to take into account the coordinates of touch events, but fails miserably by only querying the TouchList inoriginalEvent.touches
and foregoing the one inoriginalEvent.changedTouches
. This gimps draggable and droppable events on any modern touch-supported browser.