Touch Action 触摸操作
在触摸屏上控制元素滚动和缩放的实用工具。
| Class | Properties |
|---|
基本用法
设置触摸操作
使用 touch-{action} 实用程序来控制在触摸屏上如何滚动(平移)和缩放(捏合)元素。
👆 在图像网格中滚动以查看预期行为
touch-auto

touch-none

touch-pan-x

touch-pan-y

html
<div class="w-full h-48 overflow-auto touch-auto ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-none ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-pan-x ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>
<div class="w-full h-48 overflow-auto touch-pan-y ...">
<img class="w-[150%] max-w-none h-auto" src="..." />
</div>有条件地应用
悬停、焦点和其他状态
Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:touch-pan-x 只在悬停时应用 touch-pan-x 实用程序。
html
<div class="hover:touch-pan-x">
<!-- ... -->
</div>有关所有可用状态修饰符的完整列表,请查看悬停、焦点和其他状态文档。
断点和媒体查询
您还可以使用变体修饰符来针对响应式断点、深色模式、偏好减少动作等媒体查询进行定位。例如,使用 md:touch-pan-x 仅在中等屏幕尺寸及以上应用 touch-pan-x 实用程序。
html
<div class="md:touch-pan-x">
<!-- ... -->
</div>