Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 3, 2026·3 min de lecture

interact.js — Drag, Resize, and Multi-Touch Gestures for the Web

A JavaScript library for drag-and-drop, resizing, and multi-touch gesture handling that works with mouse, touch, and pointer events through a unified API.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
interact.js Overview
Commande d'installation directe
npx -y tokrepo@latest install e666a4d4-7705-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

interact.js provides a unified API for implementing drag-and-drop, resizing, and multi-touch gestures in web applications. It normalizes mouse, touch, and pointer events into a consistent interface, making it straightforward to build interactive interfaces that work across desktop and mobile devices.

What interact.js Does

  • Enables drag-and-drop with inertia and snap-to-grid capabilities
  • Provides element resizing with customizable handles and aspect ratio locking
  • Handles multi-touch pinch, rotate, and custom gesture recognition
  • Supports drop zones with accept filters and overlap detection
  • Works with SVG elements and nested coordinate systems

Architecture Overview

interact.js operates by attaching pointer event listeners to the document and matching events to configured interactable targets. It maintains an internal interaction state machine that tracks active pointers, calculates deltas, and dispatches high-level events (dragmove, resizemove, gesturechange). Modifiers like snap, restrict, and inertia are applied as a pipeline, transforming raw pointer coordinates before they reach event listeners.

Self-Hosting & Configuration

  • Install via npm and import, or load from a CDN
  • Chain .draggable(), .resizable(), and .gesturable() on any CSS selector
  • Use modifiers like interact.modifiers.snap() for grid alignment
  • Set restrict modifiers to contain elements within parent boundaries
  • Configure inertia: true for momentum-based movement after release

Key Features

  • Unified API across mouse, touch, and pointer events
  • Built-in snap, restrict, and inertia modifiers
  • Multi-touch gesture support for pinch and rotate
  • Drop zone management with overlap calculation modes
  • SVG-aware coordinate handling for embedded graphics

Comparison with Similar Tools

  • SortableJS — focused on list reordering; interact.js handles free-form drag, resize, and gestures
  • dnd-kit — React-specific with accessibility focus; interact.js is framework-agnostic
  • React DnD — React-only with HTML5 backend; interact.js supports multi-touch natively
  • Hammer.js — gesture-only (pinch, swipe); interact.js adds drag-and-drop and resizing

FAQ

Q: Does interact.js move elements automatically? A: No. It fires events with coordinate deltas. You apply the transform in your event listener for full control.

Q: Can I use it with React or Vue? A: Yes. interact.js is framework-agnostic. Initialize it in lifecycle hooks and clean up on unmount.

Q: Does it support touch devices? A: Yes. It handles touch, pointer, and mouse events through a unified interface with multi-touch gesture support.

Q: How does snap-to-grid work? A: Add interact.modifiers.snap({ targets: [interact.snappers.grid({ x: 30, y: 30 })] }) to your configuration.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires