jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
Draggable(hash)

Draggable(hash)

Create a draggable element with a number of advanced options including callback, Google Maps type draggables, reversion, ghosting, and grid dragging.

返回值

jQuery

参数

  • hash (Hash): A hash of parameters. All parameters are optional.

Hash 选项

  • handle (String): The jQuery selector matching the handle that starts the draggable
  • handle (DOMElement): The DOM Element of the handle that starts the draggable
  • revert (Boolean): When true, on stop-drag the element returns to initial position
  • ghosting (Boolean): When true, a copy of the element is moved
  • zIndex (Integer): zIndex depth for the element while it is being dragged
  • opacity (Float): A number between 0 and 1 that indicates the opacity of the element while being dragged
  • grid (Integer): A number of pixels indicating the grid that the element should snap to
  • grid (Array): A number of x-pixels and y-pixels indicating the grid that the element should snap to
  • fx (Integer): Duration for the effect (like ghosting or revert) applied to the draggable
  • containment (String): Define the zone where the draggable can be moved. 'parent' moves it inside parent element, while 'document' prevents it from leaving the document and forcing additional scrolling
  • containment (Array): An 4-element array (topm left, width, height) indicating the containment of the element
  • axis (String): Set an axis: vertical (with 'vertically') or horizontal (with 'horizontally')
  • onStart (Function): Callback function triggered when the dragging starts
  • onStop (Function): Callback function triggered when the dragging stops
  • onChange (Function): Callback function triggered when the dragging stop and the element was moved at least one pixel
  • onDrag (Function): Callback function triggered while the element is dragged. Receives two parameters: x and y coordinates. You can return an object with new coordinates {x: x, y: y} so this way you can interact with the dragging process (for instance, build your containment)
  • insideParent (Boolean): Forces the element to remain inside its parent when being dragged (like Google Maps)
  • snapDistance (Integer): The element is not moved unless it is dragged more than snapDistance. You can prevent accidental dragging and keep regular clicking enabled (for links or form elements, for instance)
  • cursorAt (Object): The dragged element is moved to the cursor position with the offset specified. Accepts value for top, left, right and bottom offset. Basically, this forces the cursor to a particular position during the entire drag operation.
  • autoSize (Boolean): When true, the drag helper is resized to its content, instead of the dragged element's sizes