1. 交互
  2. 触控行为

交互

touch-action

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

ClassStyles
touch-auto
touch-action: auto;
touch-none
touch-action: none;
touch-pan-x
touch-action: pan-x;
touch-pan-left
touch-action: pan-left;
touch-pan-right
touch-action: pan-right;
touch-pan-y
touch-action: pan-y;
touch-pan-up
touch-action: pan-up;
touch-pan-down
touch-action: pan-down;
touch-pinch-zoom
touch-action: pinch-zoom;
touch-manipulation
touch-action: manipulation;

示例

基本示例

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

尝试在触摸屏上平移这些图片

触摸自动

触摸无

触摸水平滑动

触摸垂直滑动

<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>

响应式设计

Prefix a touch-action utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.