Capítulo 222 de 411

Chapter 222: Draggable.create()

Core Idea

The flexible, recommended way to create Draggable instances (vs. new Draggable()) — accepts a single element, an array, or selector text, and always returns an array of instances (one per element).

Reference Tables

ParameterTypeDescription
targetObjectelement, array of elements, or selector string
varsObjectconfig like {type: "x,y", inertia: true, edgeResistance: 0.8, onDrag: fn}

Returns: Array of Draggable instances.

Code Examples

let instances = Draggable.create(".draggable", { type: "x,y", bounds: "#container" });

Key Takeaways

  1. Always returns an array, even for a single element — a Draggable instance is always tied to exactly one element.

Connects To

  • Draggable.get(): retrieves the instance for one specific element after create() made several.