📅  最后修改于: 2020-11-27 01:52:05             🧑  作者: Mango
jQueryUI sortable()方法用于通过使用鼠标对列表或网格形式的元素进行重新排序。此方法的排序能力基于作为第一个参数传递的操作字符串。
句法:
您可以两种形式使用sortable()方法:
1. $(selector, context).sortable (options) Method
2. $(selector, context).sortable ("action", params) Method
sortable(选项)方法指定HTML元素包含可互换的元素。在这里,options参数指定在重新排序过程中涉及的元素的行为。
句法:
$(selector, context).sortable (options);
以下是可与该方法一起使用的不同选项的列表:
Option | Description |
---|---|
appendto | This option specifies the element in which the new element created with options.helper will be inserted during the time of the move/drag. By default its value is parent. |
axis | This option indicates an axis of movement (“x” is horizontal, “y” is vertical). By default its value is false. |
cancel | This option is used to prevent sorting of elements by clicking on any of the selector elements. By default its value is “input,textarea,button,select,option”. |
connectwith | This option is a selector that identifies another sortable element that can accept items from this sortable. This allows items from one list to be moved to other lists, a frequent and useful user interaction. If omitted, no other element is connected. This is a one-way relationship. By default its value is false. |
containment | This option indicates an element within which the displacement takes place. The element will be represented by a selector (only the first item in the list will be considered), a DOM element, or the string “parent” (parent element) or “window” (html page). |
cursor | It specifies the cursor CSS property when the element moves. It represents the shape of the mouse pointer. By default its value is “auto”. |
cursorat | It sets the offset of the dragging helper relative to the mouse cursor. Coordinates can be given as a hash using a combination of one or two keys: { top, left, right, bottom }. By default its value is “false”. |
delay | It specifies delay in milliseconds, after which the first movement of the mouse is taken into account. The displacement may begin after that time. By default its value is “0”. |
disabled | This option if set to true, disables the sortable functionality. By default its value is false. |
distance | It indicates the number of pixels that the mouse must be moved before the sorting starts. If specified, sorting will not start until after mouse is dragged beyond distance. By default its value is “1”. |
droponempty | If you set this option to false, then items from this sortable can’t be dropped on an empty connect sortable. By default its value is true. |
forcehelpersize | If you set this option to true, it forces the helper to have a size. By default its value is false. |
forceplaceholdersize | This option when set to true, takes into account the size of the placeholder when an item is moved. This option is only useful if options.placeholder is initialized. By default its value is false. |
grid | This option is an array [x, y] indicating the number of pixels that the sorting element moves horizontally and vertically during displacement of the mouse. By default its value is false. |
handle | If specified, restricts sort from starting unless the mousedown occurs on the specified element(s). By default its value is false. |
helper | It is allowed for a helper element to be used for dragging display. By default its value is original. |
items | This option specifies which items inside the DOM element to be sorted. By default its value is > *. |
opacity | This option is used to define the opacity of the helper while sorting. By default its value is false. |
placeholder | This option is used to class name that gets applied to the otherwise white space. By default its value is false. |
revert | This option decides whether the sortable items should revert to their new positions using a smooth animation. By default its value is false. |
scroll | This option is used to enable scrolling. If you set this option to true the page scrolls when coming to an edge. By default its value is true. |
scrollsenstivity | This option indicates how many pixels the mouse must exit the visible area to cause scrolling. By default its value is 20. This option is used only with options.scroll set to true. |
scrollspeed | This option indicates the scrolling speed of the display once the scrolling begins. By default its value is 20. |
tolerance | This option is a string that specifies which mode to use for testing whether the item being moved is hovering over another item. By default its value is “intersect”. |
zIndex | This option represents z-Index for element/helper while being sorted. By default its value is 1000. |
让我们以一个简单的示例来演示可排序的功能,不将任何参数传递给sortable()方法。
jQuery UI Sortable - Example
Courses Available at JavaTpoint
- Java/J2EE
- .NET
- SQL
- PHP
- Android
- C/C++
- jQuery