LogoLogo
首页示例Github
  • 概述
  • 介绍
    • 安装指南
    • 快速开始
  • API 文档
    • DndContext
      • 碰撞检测算法
      • useDndContext
      • useDndMonitor
    • Droppable
      • useDroppable
    • Draggable
      • useDraggable
      • 拖动浮层
    • Sensors
      • Pointer
      • Mouse
      • Touch
      • Keyboard
    • Modifiers
  • 预置能力
    • Sortable
      • Sortable Context
      • useSortable
  • 指南
    • 无障碍指南
  • 说明
由 GitBook 提供支持
在本页
  • Activator
  • Activation constraints
  • Recommendations

这有帮助吗?

在GitHub上编辑
  1. API 文档
  2. Sensors

Touch

上一页Mouse下一页Keyboard

最后更新于1年前

这有帮助吗?

The Touch sensor responds to . Touch events offer the ability to interpret finger or stylus activity on touch screens or trackpads.

Activator

The touch activator is the onTouchStart event handler. The Touch sensor is initialized if the there is no more than a single touch on the property.

Activation constraints

Like the sensor, the Touch sensor has two activation constraints:

  • Distance constraint

  • Delay constraint

These activation constraints are mutually exclusive and may not be used simultaneously.

Distance

The distance constraint subscribes to the following interface:

interface DistanceConstraint {
  distance: number;
}

The distance property represents the distance, in pixels, by which the touch input needs to be moved before a drag start event is emitted.

Delay

The delay constraint subscribe to the following interface:

interface DelayConstraint {
  delay: number;
  tolerance: number;
}

The delay property represents the duration, in milliseconds, that a draggable item needs to be held by the touch input before a drag start event is emitted.

The tolerance property represents the distance, in pixels, of motion that is tolerated before the drag operation is aborted. If the finger or stylus is moved during the delay duration and the tolerance is set to zero, the drag operation will be immediately aborted. If a higher tolerance is set, for example, a tolerance of 5 pixels, the operation will only be aborted if the finger is moved by more than 5 pixels during the delay.

This property is particularly useful for touch input, where some tolerance should be accounted for when using a delay constraint, as touch input is less precise than mouse input.

Recommendations

touch-action

We highly recommend you specify the touch-action CSS property for all of your draggable elements.

In general, we recommend you set the touch-action property to manipulation for draggable elements when using the Touch sensor.

Touch events do not suffer the same limitations as Pointer events, and it is possible to prevent the page from scrolling in touchmove events.

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). Source:

Touch events
event.touches
Pointer
MDN