- CSS — touch-action
- Example
- Syntax
- Values
- Formal syntax
- Description
- Browser Compatibility
- See Also
- Specifications
- touch — action
- Кратко
- Как пишется
- touch-action
- Syntax
- Values
- Accessibility concerns
- Formal definition
- Formal syntax
- Examples
- Disabling all gestures
- HTML
- CSS
- Result
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
CSS — touch-action
The touch-action CSS property specifies whether, and in what ways, a given region can be manipulated by the user (for instance, by panning or zooming).
Example
.list < width: 200px; height: 50px; overflow-x: scroll; > .list > .entry < touch-action: pan-x; >
Syntax
/* 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: manipulation; /* Global values */ touch-action: inherit; touch-action: initial; touch-action: unset;
Values
auto The user agent may determine any permitted touch behaviors, such as panning and zooming manipulations of the viewport, for touches that begin on the element. none Use this value to disable all of the default behaviors and allow your content to handle all touch input (touches that begin on the element must not trigger default touch behaviors). pan-x The user agent may consider touches that begin on the element only for the purposes of horizontally scrolling the element’s nearest ancestor with horizontally scrollable content. pan-y The user agent may consider touches that begin on the element only for the purposes of vertically scrolling the element’s nearest ancestor with vertically scrollable content. manipulation The user agent may consider touches that begin on the element only for the purposes of scrolling and continuous zooming. Any additional behaviors supported by auto are out of scope for this specification.
This is an experimental technology
Because this technology’s specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The following property values have not yet been formally standardized. They are specified in the Pointer Events – Level 2 Editor’s Draft specification and not in Pointer Events Recommendation . These property values are not widely implemented.
pan-left , pan-right The user agent may consider touches that begin on the element only for the purposes of horizontally scrolling the element’s nearest ancestor with horizontally scrollable content. pan-up , pan-down The user agent may consider touches that begin on the element only for the purposes of vertically scrolling the element’s nearest ancestor with vertically scrollable content.
Formal syntax
auto title="Single bar" href code-leadattribute">#single_bar">|a> none title="Single bar" href code-leadattribute">#single_bar">|a> title="Brackets" href code-leadattribute">#brackets">[a> title="Brackets" href code-leadattribute">#brackets">[a> pan-x title="Single bar" href code-leadattribute">#single_bar">|a> pan-left title="Single bar" href code-leadattribute">#single_bar">|a> pan-right title="Brackets" href code-leadattribute">#brackets">]a> title="Double bar" href code-leadattribute">#double_bar">||a> title="Brackets" href code-leadattribute">#brackets">[a> pan-y title="Single bar" href code-leadattribute">#single_bar">|a> pan-up title="Single bar" href code-leadattribute">#single_bar">|a> pan-down title="Brackets" href code-leadattribute">#brackets">]a> title="Brackets" href code-leadattribute">#brackets">]a> title="Single bar" href code-leadattribute">#single_bar">|a> manipulation
Description
The touch-action CSS property specifies whether, and in what ways, a given region can be manipulated by the user (for instance, by panning or zooming).
Initial value | auto |
---|---|
Applies to | all elements except: non-replaced inline elements, table rows, row groups, table columns, and column groups |
Inherited | no |
Media | visual |
Computed value | as specified |
Animation type | discrete |
Canonical order | the unique non-ambiguous order defined by the formal grammar |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 36.0 | No support [1] | 10.0 -ms [2] 11.0 | 26.0 | No support [4] |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 37.0 | No support [1] | (Yes) | ? | 9.1 [3] |
See Also
Specifications
Specification | Status | Comment |
---|---|---|
Pointer Events – Level 2 The definition of ‘touch-action’ in that specification. | Editor’s Draft | Added property values pan-left , pan-right , pan-up , pan-down |
Pointer Events The definition of ‘touch-action’ in that specification. | Recommendation | Initial definition |
touch — action
Можно ли нажать на элемент пальцем? Что-то вроде тач-событий в JavaScript.
Время чтения: меньше 5 мин
Это незавершённая статья. Вы можете помочь её закончить! Почитайте о том, как контрибьютить в Доку.
Кратко
Скопировать ссылку «Кратко» Скопировано
Свойство touch — action позволяет контролировать то, как с элементом можно взаимодействовать на сенсорных экранах.
Как пишется
Скопировать ссылку «Как пишется» Скопировано
- none — запрещает все типы взаимодействий. Можно обрабатывать события при помощи JavaScript.
- auto — разрешает все типы взаимодействия (значение по умолчанию).
- manipulation — элемент можно сдвигать и зумить. Это сокращение для комбинации pan — x pan — y pinch — zoom . Остальные нестандартные жесты, вроде двойного тапа, запрещены.
- pan — x — элемент можно сдвигать по оси x с помощью одного пальца. Это сокращение для значений pan — left и pan — right . Может использоваться в сочетании с pan — y , pan — up , pan — down и pinch — zoom .
- pan — y — элемент можно смещать по оси y с помощью одного пальца. Это сокращение для значений pan — up и pan — down . Может использоваться в сочетании с pan — x , pan — left , pan — right и pinch — zoom .
- pan — left — элемент можно смещать только если начать движение от левого края (эксперимент).
- pan — right — элемент можно смещать только если начать движение от правого края (эксперимент).
- pan — down — элемент можно смещать только если начать движение снизу вверх (эксперимент).
- pan — up — элемент можно смещать только если начать движение сверху вниз (эксперимент).
- pinch — zoom — элемент можно зазумить щипком. Можно совместить с pan — x , pan — left , pan — right , pan — y , pan — up , pan — down .
touch-action
The touch-action CSS property sets how an element’s region can be manipulated by a touchscreen user (for example, by zooming features built into the browser).
By default, panning (scrolling) and pinching gestures are handled exclusively by the browser. An application using 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 Touch events disable the browser handling of gestures by calling 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 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 top-level elements which have some custom behavior, without needing to specify touch-action explicitly on any of that element’s descendants.
Note: After a gesture starts, changes to touch-action will not have any impact on the behavior of the current gesture.
Syntax
/* 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: revert; touch-action: revert-layer; touch-action: unset;
The touch-action property may be specified as either:
- One of the keywords auto , none , manipulation , or
- One of the keywords pan-x , pan-left , pan-right , and/or one of the keywords pan-y , pan-up , pan-down , plus optionally the keyword pinch-zoom .
Values
Enable browser handling of all panning and zooming gestures.
Disable browser handling of all panning and zooming gestures.
Enable single-finger horizontal panning gestures. May be combined with pan-y, pan-up, pan-down and/or pinch-zoom.
Enable single-finger vertical panning gestures. May be combined with pan-x, pan-left, pan-right and/or pinch-zoom.
Enable panning and pinch zoom gestures, but disable additional non-standard gestures such as double-tap to zoom. Disabling double-tap to zoom removes the need for browsers to delay the generation of click events when the user taps the screen. This is an alias for «pan-x pan-y pinch-zoom» (which, for compatibility, is itself still valid).
pan-left , pan-right , pan-up , pan-down Experimental
Enable single-finger gestures that begin by scrolling in the given direction(s). Once scrolling has started, the direction may still be reversed. Note that scrolling «up» (pan-up) means that the user is dragging their finger downward on the screen surface, and likewise pan-left means the user is dragging their finger to the right. Multiple directions may be combined except when there is a simpler representation (for example, «pan-left pan-right» is invalid since «pan-x» is simpler, but «pan-left pan-down» is valid).
Enable multi-finger panning and zooming of the page. This may be combined with any of the pan- values.
Accessibility concerns
A declaration of touch-action: none; may inhibit operating a browser’s zooming capabilities. This will prevent people experiencing low vision conditions from being able to read and understand page content.
Formal definition
Initial value | auto |
---|---|
Applies to | all elements except: non-replaced inline elements, table rows, row groups, table columns, and column groups |
Inherited | no |
Computed value | as specified |
Animation type | Not animatable |
Formal syntax
touch-action =
auto |
none |
[ [ pan-x | pan-left | pan-right ] || [ pan-y | pan-up | pan-down ] || pinch-zoom ] |
manipulation
Examples
Disabling all gestures
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.
HTML
CSS
#map height: 150vh; width: 70vw; background: linear-gradient(blue, green); touch-action: none; >
Result
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 20, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.