# Sortable
Sortable is a minimalist JavaScript library for reorderable drag-and-drop lists.
Demo: http://rubaxa.github.io/Sortable/
## Features
* Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers (including IE9)
* Can drag from one list to another or within the same list
* CSS animation when moving items
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
* Smart auto-scrolling
* Built using native HTML5 drag and drop API
* Supports
* [Meteor](https://github.com/SortableJS/meteor-sortablejs)
* AngularJS
* [2.0+](https://github.com/SortableJS/angular-sortablejs)
* [1.*](https://github.com/SortableJS/angular-legacy-sortablejs)
* React
* [ES2015+](https://github.com/SortableJS/react-sortablejs)
* [Mixin](https://github.com/SortableJS/react-mixin-sortablejs)
* [Knockout](https://github.com/SortableJS/knockout-sortablejs)
* [Polymer](https://github.com/SortableJS/polymer-sortablejs)
* [Vue](https://github.com/SortableJS/Vue.Draggable)
* Supports any CSS library, e.g. [Bootstrap](#bs)
* Simple API
* [CDN](#cdn)
* No jQuery (but there is [support](#jq))
<br/>
### Articles
* [Sortable v1.0 — New capabilities](https://github.com/RubaXa/Sortable/wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014)
* [Sorting with the help of HTML5 Drag'n'Drop API](https://github.com/RubaXa/Sortable/wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013)
<br/>
### Install
Via npm
```bash
$ npm install sortablejs --save
```
Via bower:
```bash
$ bower install --save sortablejs
```
<br/>
### Usage
```html
<ul id="items">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
```
```js
var el = document.getElementById('items');
var sortable = Sortable.create(el);
```
You can use any element for the list and its elements, not just `ul`/`li`. Here is an [example with `div`s](http://jsbin.com/luxero/2/edit?html,js,output).
---
### Options
```js
var sortable = new Sortable(el, {
group: "name", // or { name: "...", pull: [true, false, clone], put: [true, false, array] }
sort: true, // sorting inside list
delay: 0, // time in milliseconds to define when the sorting should start
disabled: false, // Disables the sortable if set to true.
store: null, // @see Store
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
handle: ".my-handle", // Drag handle selector within list items
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
draggable: ".item", // Specifies which items inside the element should be draggable
ghostClass: "sortable-ghost", // Class name for the drop placeholder
chosenClass: "sortable-chosen", // Class name for the chosen item
dragClass: "sortable-drag", // Class name for the dragging item
dataIdAttr: 'data-id',
forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in
fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback
fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
scroll: true, // or HTMLElement
scrollFn: function(offsetX, offsetY, originalEvent) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
scrollSpeed: 10, // px
setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {
dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
},
// Element is chosen
onChoose: function (/**Event*/evt) {
evt.oldIndex; // element index within parent
},
// Element dragging started
onStart: function (/**Event*/evt) {
evt.oldIndex; // element index within parent
},
// Element dragging ended
onEnd: function (/**Event*/evt) {
evt.oldIndex; // element's old index within parent
evt.newIndex; // element's new index within parent
},
// Element is dropped into the list from another list
onAdd: function (/**Event*/evt) {
var itemEl = evt.item; // dragged HTMLElement
evt.from; // previous list
// + indexes from onEnd
},
// Changed sorting within list
onUpdate: function (/**Event*/evt) {
var itemEl = evt.item; // dragged HTMLElement
// + indexes from onEnd
},
// Called by any change to the list (add / update / remove)
onSort: function (/**Event*/evt) {
// same properties as onUpdate
},
// Element is removed from the list into another list
onRemove: function (/**Event*/evt) {
// same properties as onUpdate
},
// Attempt to drag a filtered element
onFilter: function (/**Event*/evt) {
var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event.
},
// Event when you move an item in the list or between lists
onMove: function (/**Event*/evt, /**Event*/originalEvent) {
// Example: http://jsbin.com/tuyafe/1/edit?js,output
evt.dragged; // dragged HTMLElement
evt.draggedRect; // TextRectangle {left, top, right и bottom}
evt.related; // HTMLElement on which have guided
evt.relatedRect; // TextRectangle
originalEvent.clientY; // mouse position
// return false; — for cancel
},
// Called when creating a clone of element
onClone: function (/**Event*/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
}
});
```
---
#### `group` option
To drag elements from one list into another, both lists must have the same `group` value.
You can also define whether lists can give away, give and keep a copy (`clone`), and receive elements.
* name: `String` — group name
* pull: `true|false|'clone'|function` — ability to move from the list. `clone` — copy the item, rather than move.
* put: `true|false|["foo", "bar"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be taken.
Demo:
- http://jsbin.com/naduvo/edit?js,output
- http://jsbin.com/rusuvot/edit?js,output — use of complex logic in the `pull` and` put`
---
#### `sort` option
Sorting inside list.
Demo: http://jsbin.com/xizeh/2/edit?html,js,output
---
#### `delay` option
Time in milliseconds to define when the sorting should start.
Demo: http://jsbin.com/xizeh/4/edit?html,js,output
---
#### `disabled` options
Disables the sortable if set to `true`.
Demo: http://jsbin.com/xiloqu/1/edit?html,js,output
```js
var sortable = Sortable.create(list);
document.getElementById("switcher").onclick = function () {
var state = sortable.option("disabled"); // get
sortable.option("disabled", !state); // set
};
```
---
#### `handle` option
To make list items draggable, Sortable disables text selection by the user.
That's not always desirable. To allow text selection, define a drag handler,
which is an area of every list element that allows it to be dragged around.
Demo: http://jsbin.com/newize/1/edit?html,js,output
```js
Sortable.create(el, {
handle: ".my-handle"
});
```
```html
<ul>
<li><span class="my-handle">::</span> list item text one
<li><span class="my-handle">::</span> list item text two
</ul>
```
```css
.my-handle {
cursor: move;
cursor: -webkit-grabbing;
}
```
---
#### `filter` option
```js
Sortable.create(list, {
filter: ".js-remove, .js-edit",
onFilter: function (evt) {
var item = evt.item,
ctrl = evt.target;
if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button
item.parentNode.removeChild(item); // remove sortable item
}
else if (Sortable.utils.is(ctrl, ".js-edit")) { // Click on edit link
// ...
}
}
})
```
---
#### `ghostClass` option
Class name for the drop placeholder (default `sortable-ghost`).
Demo: http://jsbin.com/hunifu/1/edit?css,js,output
```css
.ghost {
opacity: 0.4;
}
```
```js
Sortable.create(list, {
ghostClass
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
仿Rose聚合直播盒子源码+后台,附安装搭建教程 (2000个子文件)
组件区图标.bmp 4MB
设计区图标.bmp 4MB
属性区图标.bmp 4MB
设计区图标.bmp 554KB
设计区图标.bmp 539KB
设计区图标.bmp 338KB
设计区图标.bmp 257KB
属性区图标.bmp 257KB
组件区图标.bmp 257KB
属性区图标.bmp 257KB
设计区图标.bmp 257KB
组件区图标.bmp 257KB
设计区图标.bmp 217KB
设计区图标.bmp 55KB
设计区图标.bmp 48KB
属性区图标.bmp 48KB
组件区图标.bmp 48KB
设计区图标.bmp 33KB
设计区图标.bmp 23KB
属性区图标.bmp 23KB
组件区图标.bmp 23KB
属性区图标.bmp 23KB
设计区图标.bmp 23KB
组件区图标.bmp 23KB
组件区图标.bmp 14KB
设计区图标.bmp 14KB
属性区图标.bmp 14KB
设计区图标.bmp 12KB
属性区图标.bmp 11KB
设计区图标.bmp 11KB
组件区图标.bmp 11KB
属性区图标.bmp 9KB
设计区图标.bmp 9KB
组件区图标.bmp 9KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
组件区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
设计区图标.bmp 2KB
组件区图标.bmp 2KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
阿里聚合发布
- 粉丝: 101
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页