Skip to content
全部文档

touch-action

用于控制元素在触屏上如何滚动和缩放的工具类。

快速参考

属性
touch-autotouch-action: auto;
touch-nonetouch-action: none;
touch-pan-xtouch-action: pan-x;
touch-pan-lefttouch-action: pan-left;
touch-pan-righttouch-action: pan-right;
touch-pan-ytouch-action: pan-y;
touch-pan-uptouch-action: pan-up;
touch-pan-downtouch-action: pan-down;
touch-pinch-zoomtouch-action: pinch-zoom;
touch-manipulationtouch-action: manipulation;

示例

基础示例

使用 touch-pan-ytouch-pinch-zoom 等工具类,控制元素在触屏上如何滚动(平移)和缩放(捏合):

touch-auto

touch-none

touch-pan-x

touch-pan-y

html
<!-- [!code classes:overflow-auto,touch-auto,touch-none,touch-pan-x,touch-pan-y] -->
<div class="h-48 w-full touch-auto overflow-auto ...">
  <img class="h-auto w-[150%] max-w-none" src="..." />
</div>
<div class="h-48 w-full touch-none overflow-auto ...">
  <img class="h-auto w-[150%] max-w-none" src="..." />
</div>
<div class="h-48 w-full touch-pan-x overflow-auto ...">
  <img class="h-auto w-[150%] max-w-none" src="..." />
</div>
<div class="h-48 w-full touch-pan-y overflow-auto ...">
  <img class="h-auto w-[150%] max-w-none" src="..." />
</div>

响应式设计

使用 md: 等断点变体为 touch-action 工具类添加前缀,使其仅在中等及以上屏幕尺寸生效:

html
<div class="touch-pan-x md:touch-auto ...">
 <!-- ... -->
</div>

变体文档 中了解如何使用变体。

文档译文以 MIT 协议授权;原文版权归 Tailwind Labs。湘ICP备2026005453号-2