本页出处
设计风格资料库
内容来自 luckymaomi 的 UI 风格库(复刻版),以 MIT 许可 提供。本站镜像收录,仅作学习参考;这一页的原始地址是 原站页面。
← 回到导览访问原站仓库
返回动效库
指针高级

拖拽物理

拖拽对象带有惯性、吸附或回弹,提升画布类工具的手感。

手动触发continuous

交互预览

动效定义与代码

{
  "slug": "drag-physics",
  "name": "拖拽物理",
  "nameEn": "Drag Physics",
  "description": "拖拽对象带有惯性、吸附或回弹,提升画布类工具的手感。",
  "descriptionEn": "Dragged objects include inertia, snap, or spring-back behavior to improve canvas-like tools.",
  "category": "pointer",
  "tags": [
    "drag",
    "physics",
    "inertia",
    "pointer"
  ],
  "trigger": "manual",
  "difficulty": "advanced",
  "duration": "continuous",
  "easing": "spring",
  "cssProperties": [
    "transform"
  ],
  "isGPUAccelerated": true,
  "previewBg": "light",
  "keywords": [
    "drag physics",
    "inertia",
    "spring drag",
    "pointer capture"
  ],
  "useCases": [
    "Canvas tools",
    "Whiteboards",
    "Sortable cards"
  ],
  "relatedAnimations": [
    "elastic-snap",
    "magnetic-hover"
  ],
  "recommendedStyles": [
    "dashboard-layout",
    "data-dense",
    "soft-ui"
  ],
  "playgroundMode": "js-driven",
  "intensity": "medium",
  "input": "pointer-any",
  "performanceNotes": "Use pointer capture, transform writes, and clamp boundaries before applying spring/inertia.",
  "accessibilityNotes": "Provide keyboard alternatives for drag targets and announce reorder changes when relevant.",
  "recommendedUseCases": [
    "Whiteboards",
    "Kanban cards",
    "Creative tools"
  ],
  "codeSnippets": [
    {
      "label": "Pointer Capture",
      "language": "tsx",
      "code": "function onPointerDown(event: React.PointerEvent<HTMLElement>) {\n  event.currentTarget.setPointerCapture(event.pointerId);\n  // Store start pointer and element positions in refs.\n}\n\nfunction onPointerMove(event: React.PointerEvent<HTMLElement>) {\n  if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;\n  // Write translate3d(x, y, 0), then snap or spring on release.\n}"
    }
  ]
}