docs.rodeo

MDN Web Docs mirror

TouchEvent

{{APIRef("Touch Events")}} 

The TouchEvent interface represents an {{domxref("UIEvent")}}  which is sent when the state of contacts with a touch-sensitive surface changes. This surface can be a touch screen or trackpad, for example. The event can describe one or more points of contact with the screen and includes support for detecting movement, addition and removal of contact points, and so forth.

Touches are represented by the {{domxref("Touch")}}  object; each touch is described by a position, size and shape, amount of pressure, and target element. Lists of touches are represented by {{domxref("TouchList")}}  objects.

{{InheritanceDiagram}} 

Constructor

Instance properties

This interface inherits properties from its parent, {{domxref("UIEvent")}}  and {{domxref("Event")}} .

Touch event types

There are several types of event that can be fired to indicate that touch-related changes have occurred. You can determine which of these has happened by looking at the event’s {{domxref("event.type", "TouchEvent.type")}}  property.

Using with addEventListener() and preventDefault()

It’s important to note that in many cases, both touch and mouse events get sent (in order to let non-touch-specific code still interact with the user). If you use touch events, you should call {{domxref("Event.preventDefault","preventDefault()")}}  to keep the mouse event from being sent as well.

The exception to this is Chrome, starting with version 56 (desktop, Chrome for Android, and Android webview), where the default value for the passive option for {{domxref("Element/touchstart_event", "touchstart")}}  and {{domxref("Element/touchmove_event", "touchmove")}}  is true and calls to {{domxref("Event.preventDefault","preventDefault()")}}  will have no effect. To override this behavior, you need to set the passive option to false, after which calling {{domxref("Event.preventDefault","preventDefault()")}}  will work as specified. The change to treat listeners as passive by default prevents the listener from blocking page rendering while a user is scrolling. A demo is available on the Chrome Developer site.

Example

See the example on the main Touch events article.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN