--- title: touch-action slug: Web/CSS/touch-action translation_of: Web/CSS/touch-action ---
A propriedade touch-action
é uma especificação CSS , e forma, uma determinada região que pode ser manipulada pelo usuário através de uma tela sensível ao toque (por exemplo, recursos panorâmicos ou de zoom incorporados no navegador).
/* Keyword values */ touch-action: auto; touch-action: none; touch-action: pan-x; touch-action: pan-left; touch-action: pan-right; touch-action: pan-y; touch-action: pan-up; touch-action: pan-down; touch-action: pinch-zoom; touch-action: manipulation; /* Global values */ touch-action: inherit; touch-action: initial; touch-action: unset;
{{cssinfo}}
By default, panning (scrolling) and pinching gestures are handled exclusively by the browser. An application using {{domxref("Pointer_events")}} will receive a pointercancel
event when the browser starts handling a touch gesture. By explicitly specifying which gestures should be handled by the browser, an application can supply its own behavior in pointermove
and pointerup
listeners for the remaining gestures. Applications using {{domxref("Touch_events")}} disable the browser handling of gestures by calling {{domxref("Event.preventDefault","preventDefault()")}}, but should also use touch-action to ensure the browser knows the intent of the application before any event listeners have been invoked.
When a gesture is started, the browser intersects the touch-action values of the touched element and all its ancestors up to the one that implements the gesture (in other words, the first containing scrolling element). This means that in practice, touch-action is typically applied only to individual elements which have some custom behavior, without needing to specify touch-action explicitly on any of that element's descendants. After a gesture has started, changes to touch-action values will not have any impact on the behavior of the current gesture.
The touch-action
property may be specified as either:
auto
, none
, manipulation
, orpan-x
, pan-left
, pan-right
, and/or one of the keywords pan-y
, pan-up
, pan-down
, plus optionally the keyword pinch-zoom
.auto
none
pan-x
pan-y
manipulation
pan-left
, pan-right,pan-up,pan-down
{{experimental_inline}}pinch-zoom
The most common usage is to disable all gestures on an element (and its non-scrollable descendants) that provides its own dragging and zooming behavior – such as a map or game surface.
#map { touch-action: none; }
Another common pattern is that of an image carousel which uses pointer events to handle horizontal panning, but doesn't want to interfere with vertical scrolling or zooming of the document.
.image-carousel { width: 100%; height: 150px; touch-action: pan-y pinch-zoom; }
touch-action is also often used to completely disable the delay of click events caused by support for the double-tap to zoom gesture.
html { touch-action: manipulation; }
Specification | Status | Comment |
---|---|---|
{{SpecName('Compat', '#touch-action', 'touch-action')}} | {{Spec2('Compat')}} | Added pinch-zoom property value. |
{{SpecName('Pointer Events 2', '#the-touch-action-css-property', 'touch-action')}} | {{Spec2('Pointer Events 2')}} | Added pan-left , pan-right , pan-up , pan-down property values. |
{{SpecName('Pointer Events', '#the-touch-action-css-property', 'touch-action')}} | {{Spec2('Pointer Events')}} | Initial definition |
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{compat("css.properties.touch-action")}}