Add Event Listeners
Touch events and mouse events are implemented on most mobile browsers.
The event names you need to implement are
touchstart
,
touchmove
,
touchend
and
touchcancel
.
For some situations, you may find that you would like to support mouse interaction as well; which you can do with the mouse events:
mousedown
,
mousemove
, and
mouseup
.
For Windows Touch devices, you need to support Pointer Events which are a new set of events. Pointer Events merge mouse and touch events into one set of callbacks. This is currently only supported in Internet Explorer 10+ with the prefixed events
MSPointerDown
,
MSPointerMove
, and
MSPointerUp
and in IE 11+ the unprefixed events
pointerdown
,
pointermove
, and
pointerup
.
Touch, mouse and Pointer Events are the building blocks for adding new gestures into your application (see
Touch, mouse and Pointer events
).
Include these event names in the
addEventListener()
method, along with the event’s callback function and a boolean. The boolean determines whether you should catch the event before or after other elements have had the opportunity to catch and interpret the events (
true
means we want the event before other elements).