拖拽-Sortable的使用
- 地址:https://github.com/SortableJS/Sortable#invertedswapthreshold-option;
- 例子:
html部分:
<ul id="items"><li>item 1</li><li>item 2</li><li>item 3</li></ul>
js部分
var el = document.getElementById('items');
// 创建sortable实例
// 方法一
// var sortable = Sortable.create(el);
// 方法二
var sortable = new Sortable(el, {group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }sort: true, // sorting inside listdelay: 0, // time in milliseconds to define when the sorting should startdelayOnTouchOnly: false, // only delay if user is using touchtouchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag eventdisabled: false, // Disables the sortable if set to true.store: null, // @see Storeanimation: 150, // ms, animation speed moving items when sorting, `0` — without animationeasing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples.handle: ".my-handle", // Drag handle selector within list items // 点击图标拖动filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`draggable: ".item", // Specifies which items inside the element should be draggabledataIdAttr: 'data-id', // HTML attribute that is used by the `toArray()` methodghostClass: "sortable-ghost", // Class name for the drop placeholderchosenClass: "sortable-chosen", // Class name for the chosen itemdragClass: "sortable-drag", // Class name for the dragging itemswapThreshold: 1, // Threshold of the swap zoneinvertSwap: false, // Will always use inverted swap zone if set to trueinvertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default)direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given)forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick infallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallbackfallbackOnBody: false, // Appends the cloned DOM Element into the Document's BodyfallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.dragoverBubble: false,removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding itemptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into itsetData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent},// Element is chosenonChoose: function (/**Event*/evt) {evt.oldIndex; // element index within parent},// Element is unchosenonUnchoose: function(/**Event*/evt) {// same properties as onEnd},// Element dragging startedonStart: function (/**Event*/evt) {evt.oldIndex; // element index within parent},// Element dragging endedonEnd: function (/**Event*/evt) {var itemEl = evt.item; // dragged HTMLElementevt.to; // target listevt.from; // previous listevt.oldIndex; // element's old index within old parentevt.newIndex; // element's new index within new parentevt.oldDraggableIndex; // element's old index within old parent, only counting draggable elementsevt.newDraggableIndex; // element's new index within new parent, only counting draggable elementsevt.clone // the clone elementevt.pullMode; // when item is in another sortable: `"clone"` if cloning, `true` if moving},// Element is dropped into the list from another listonAdd: function (/**Event*/evt) {// same properties as onEnd},// Changed sorting within listonUpdate: function (/**Event*/evt) {// same properties as onEnd},// Called by any change to the list (add / update / remove)onSort: function (/**Event*/evt) {// same properties as onEnd},// Element is removed from the list into another listonRemove: function (/**Event*/evt) {// same properties as onEnd},// Attempt to drag a filtered elementonFilter: function (/**Event*/evt) {var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event.},// Event when you move an item in the list or between listsonMove: function (/**Event*/evt, /**Event*/originalEvent) {// Example: https://jsbin.com/nawahef/edit?js,outputevt.dragged; // dragged HTMLElementevt.draggedRect; // DOMRect {left, top, right, bottom}evt.related; // HTMLElement on which have guidedevt.relatedRect; // DOMRectevt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by defaultoriginalEvent.clientY; // mouse position// return false; — for cancel// return -1; — insert before target// return 1; — insert after target// return true; — keep default insertion point based on the direction// return void; — keep default insertion point based on the direction},// Called when creating a clone of elementonClone: function (/**Event*/evt) {var origEl = evt.item;var cloneEl = evt.clone;},// Called when dragging element changes positiononChange: function(/**Event*/evt) {evt.newIndex // most likely why this event is used is to get the dragging element's current index// same properties as onEnd}
});
拖拽-Sortable的使用相关推荐
- vue+sortable实现表格拖拽
vue+sortable实现表格拖拽 前言: 支持 vue3.0 支持表格拖拽 支持自定义拖拽 sortable官网 一.下载 sortable npm install sortablejs --sa ...
- jquery的sortable拖拽排序插件,顺序没发生改变则不请求
一.前言 前几天刚做完排序,本来以为没什么问题的,结果今天被告知要优化一下..功能上是没问题,但是有一些小细节需要优化.比如我做的是每次拖拽完成之后,都在stop方法里面请求ajax保存顺序.但是要考 ...
- jquery的sortable拖拽排序问题,在页面上多次拖拽保存顺序之后,刷新页面,排序出现紊乱
一.前言 这篇博客是因为我在做完拖拽保存之后,测试多次拖拽,然后刷新页面,发现保存的顺序出来紊乱.这就很无奈了啊,打印各项数据才发现,因为保存用的是ajax的方式,所以页面上的列表序号是固定的,比如列 ...
- sortable vue 排序_VUE +element el-table运用sortable 拖拽table排序,实现行排序,列排序...
sortable.js是一款轻量级的拖放排序列表的js插件(虽然体积小,但是功能很强大) 项目需求是要求能对element中 的table进行拖拽行排序 这里用到了sorttable sortable ...
- javascript --- Sortable一个拖拽的接口
最近项目里面要实现需要实现一个拖拽功能,自己实现很麻烦,就在网上找到了一个封装好的sortable函数,github(https://github.com/SortableJS/Sortable). ...
- html列表拖拽排序插件,JS拖拽排序插件Sortable.js用法实例分析
本文实例讲述了JS拖拽排序插件Sortable.js用法.分享给大家供大家参考,具体如下: 最近由于项目功能设计的原因,需要对table中的行实现拖拽排序功能,找来找去发现Sortable.js能很好 ...
- 全网为数不多清晰可行的在VUE中使用sortable.js实现动态拖拽排序的教程!
目录 0 写在前面的 1 依赖安装 2 手写简单标签演示 3 要点 4 效果 0 写在前面的 首先批评以下文章 (10条消息) sortable.js 实现拖拽_sortablejs_花铛的博客-CS ...
- sortable使用小知识(vue)-- 使用sortable拖拽插件在初始化循环标签的状态下,如何获取拖拽的数据
废话 大家搜索这个基本都知道这个插件是干啥的,那我就不废话了.如果真的有人不晓得的话,点这个: sortable.js中文文档. 问题场景 当时产品拿着一个示例给我,我就要做成这样的. emmm,我看 ...
- Sortable简单好用的拖拽排序工具
Sortable超简单好用的拖拽排序工具 很好的拖拽排序工具,支持原始js,vue ,react,angular,可惜官网访问太慢,将文档整理放博客里,随时访问,https://www.npmjs.c ...
最新文章
- LR学习笔记三 之 界面分析
- 如何添加Samba用户
- 2.两个VLAN通过一个交换机与路由器的连接
- [网络开发]服务器开发
- 转载 - 整数划分问题
- java变量小明扑克牌_算法练习篇之:扑克牌顺子
- 网页制作中点一张图片变成图片浏览式_网页不会做,那是画册看得少(上)
- android textview字体贴底部,在android中底部设置textview
- php 警告方法 不可用,升级PHP版本后警告信息的逐一解决
- 大一计算机基础重点知识,2015-大一计算机基础知识点归纳.doc
- 《通信技术 - 以太网》详解以太网(二)
- Layui Select四级联动效果触发
- git从克隆项目到本地分支和远程分支关联
- ASP.net 密码加密和使用密码登录
- 2017 ACM ICPC Asia Regional - Daejeon Programming Constest
- NABCD 分析 - TEAM LESS ERROR
- 基于springboot的汽车配件管理系统
- 【USRP】使用USRP制作超级跑马机(手动滑稽)
- W13电力线载波通信技术
- 关于adrduino HX711库的解析
热门文章
- CentOS OpenStack Pike tacker 之 mistral 安装实录
- 宠物app如何借助大数据分析提供更贴心的宠物养护
- linux adb 权限不够,root后adb shell权限问题
- activiti 定时事件
- Android 文件加密及解密
- 公司使用电脑监控软件会怎么样?
- 计算机未来很火的方向,未来5年,这6个专业很“火热”,毕业不愁没工作
- Metropolis-Hasting抽样算法
- Jsch访问代理机报proxy error:Forbidden
- 【PySpark学习笔记三】spark-submit命令详解