--- title: touch-action slug: Web/CSS/touch-action tags: - CSS - CSS Property - Pointer Events - Reference - 'recipe:css-property' - ポインターイベント translation_of: Web/CSS/touch-action ---
{{CSSRef}}
CSS の touch-action プロパティは、タッチ画面のユーザーが要素のある領域をどのように操作できるか (例えば、ブラウザー内に組み込まれたパンまたはズーム機能) を設定します。
/* キーワード値 */ 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; /* グローバル値 */ touch-action: inherit; touch-action: initial; touch-action: unset;
既定で、パン (スクロール) およびピンチ操作はブラウザーとは独立して別に扱われます。{{domxref("Pointer_events", "ポインターイベント", "", 1)}}を使用するアプリケーションは、ブラウザーがタッチジェスチャーの扱いを始めるときに {{domxref("HTMLElement/pointercancel_event", "pointercancel")}} イベントを受け取ります。ブラウザーがどのジェスチャーを扱うかについての具体的に定義することによって、アプリケーションはジェスチャーを記憶するために {{domxref("HTMLElement/pointermove_event", "pointermove")}} および {{domxref("HTMLElement/pointerup_event", "pointerup")}} リスナーの中で独自の振る舞いを提供することができます。{{domxref("Touch_events", "タッチイベント", "", 1)}}を使用するアプリケーションは、 {{domxref("Event.preventDefault","preventDefault()")}} を呼び出すことでブラウザーがジェスチャーを扱うのを無効にすることができますが、イベントリスナーが呼び出される前に、 touch-action を使用してブラウザーにアプリケーションの目的を知らせるようにもしてください。
ジェスチャーが開始されると、ブラウザーはタッチ要素の touch-action の値を、祖先のうちジェスチャーを実装しているもの (言い換えれば、最初のスクロールを含む要素) まで交差させます。つまり実際には、 touch-action は通常、その要素の子孫のいずれかに touch-action を明示的に指定する必要なく、独自の動作を持つ最上位の要素にのみ適用されます。
ジェスチャーが開始された後、 touch-action の値を変更しても、現在のジェスチャーの動作には影響を与えません。
touch-action プロパティは次の何れかの形で指定することができます。
auto, none, manipulation のキーワードのうち一つと、またはpan-x, pan-left, pan-right, and/or one of the keywords pan-y, pan-up, pan-down, のキーワードのうち一つと、加えて任意のキーワード pinch-zoom。autononepan-xpan-ymanipulationpan-left, pan-right, pan-up, pan-down {{experimental_inline}}pinch-zoomtouch-action: none; の宣言は、ブラウザー内蔵のズーム機能を操作することを阻害することがあります。これは弱視の人がページのコンテンツを読んで理解できるようになることを阻害します。
{{CSSInfo}}
最も一般的な使い方は、要素 (およびスクロールしないその子孫) のすべてのジェスチャーを無効にして、地図やゲームの画面のように、独自のドラッグやズームの振る舞いを提供することです。
<div id="map"></div>
#map {
height: 400px;
width: 400px;
background: blue;
touch-action: none;
}
{{EmbedLiveSample('Disabling_all_gestures')}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('Compat', '#touch-action', 'touch-action')}} | {{Spec2('Compat')}} | pinch-zoom プロパティ値を追加。 |
| {{SpecName('Pointer Events 3', '#the-touch-action-css-property', 'touch-action')}} | {{Spec2('Pointer Events 3')}} | pan-left, pan-right, pan-up, pan-down プロパティ値を追加。 |
| {{SpecName('Pointer Events 2', '#the-touch-action-css-property', 'touch-action')}} | {{Spec2('Pointer Events 2')}} | 最新の勧告 |
| {{SpecName('Pointer Events', '#the-touch-action-css-property', 'touch-action')}} | {{Spec2('Pointer Events')}} | 初回定義 |
{{compat("css.properties.touch-action")}}