jQuery UI Examples - Draggable
Allows elements to be moved with the mouse.
For more details about the draggable interaction, see the API documentation Draggable Widget。
Default functionality
Enables draggable functionality on any DOM element. Move the draggable object by clicking with the mouse and dragging it in the viewport.
jQuery UI 拖动(Draggable) - 默认功能
Auto scroll
Automatically scrolls the document when the draggable is moved outside the viewport. Set the scroll option to true to enable auto scrolling, fine-tune when scrolling is triggered, and set the scroll speed through the scrollSensitivity and scrollSpeed option.
jQuery UI 拖动(Draggable) - 自动滚动
Constrain movement
Constrains the movement of each draggable by defining the boundaries of the draggable area. Set the axis option to restrict the draggable's path to the x-axis or y-axis, or use the containment option to specify a parent DOM element or a jQuery selector, such as 'document.'
jQuery UI 拖动(Draggable) - 约束运动
沿着轴约束运动:
或者在另一个 DOM 元素中约束运动:
Cursor style
Positions the cursor when dragging an object. By default, the cursor appears in the middle of the dragged object. Use the cursorAt option to specify a different position relative to the draggable (give a pixel value relative to top, right, bottom, or left). Customize the cursor's appearance by providing a cursor option with a valid CSS cursor value. Valid CSS cursor values include: default, move, pointer, crosshair, and so on.
jQuery UI 拖动(Draggable) - 光标样式
Delayed start
Pass delay option sets the number of milliseconds to delay before starting the drag. Through the distance option, dragging is allowed only after the cursor is pressed and has moved the specified number of pixels.
jQuery UI 拖动(Draggable) - 延迟开始
Events
on the draggable start、drag and stop event. Triggered when dragging starts, the start event is triggered during dragging, and the drag event is triggered when dragging stops. stop events.
jQuery UI 拖动(Draggable) - 事件
Handles
Allows dragging only when the cursor is over a specified part of the draggable. Use the handle option to specify a jQuery selector for the element (or group of elements) used to drag the object.
Or disallows dragging when the cursor is over a specified element (or group of elements) inside the draggable. Use the cancel option to specify a jQuery selector that cancels the drag functionality.
jQuery UI 拖动(Draggable) - Handles
Revert position
When a draggable with the boolean revert option set stops dragging, returns the draggable (or its helper) to its original position.
jQuery UI 拖动(Draggable) - 还原位置
Snap to element or grid
Snaps the draggable to the inner or outer boundaries of a DOM element. Use the snap、snapMode(inner, outer, both) and the snapTolerance(the distance in pixels between the draggable and the element when snapping) option.
Or snaps the draggable to a grid. Set the grid option to set the size of the grid cells (height or width in pixels).
jQuery UI 拖动(Draggable) - 对齐到元素或网格
Visual feedback
Provides feedback to the user by dragging an object as a helper.helper option accepts the value 'original' (move the draggable object with the cursor), 'clone' (move a copy of the draggable with the cursor), or a function returning a DOM element (shown near the cursor during the drag). Through the opacity option, the helper's opacity is controlled.
To distinguish which draggable is being dragged, keep the moving draggable in front. While dragging, use the zIndex option to set a high z-index for the helper, or use the stack option to ensure that when dragging stops, the last dragged item always appears above the other items in the same group.
jQuery UI 拖动(Draggable) - 视觉反馈
助手:
堆叠:
jQuery UI Draggable + Sortable
Seamless interaction between Draggable and Sortable.
jQuery UI 拖动(Draggable) + 排序(Sortable)
- 请拖拽我
- Item 1
- Item 2
- Item 3
- Item 4
- Item 5