10sortable.js dataIdAttr 获取排序后的数据
This commit is contained in:
parent
584d565d86
commit
e8fc5a4b44
|
@ -0,0 +1,64 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>sortable.js dataIdAttr属性例子</title>
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
|
||||||
|
<script src="https://www.itxst.com/package/sortable/sortable.min.js"></script>
|
||||||
|
<style>
|
||||||
|
.itxst {
|
||||||
|
margin: 10px auto;
|
||||||
|
width: 40%;
|
||||||
|
float: left;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itxst div {
|
||||||
|
padding: 6px;
|
||||||
|
background-color: #fdfdfd;
|
||||||
|
border: solid 1px #eee;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: move;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tips {
|
||||||
|
border: solid 1px #fff !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msg {
|
||||||
|
clear: both;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="box">
|
||||||
|
<div id="g1" class="itxst">
|
||||||
|
<div class="tips">dataIdAttr设置dataId属性</div>
|
||||||
|
<div class="item" data-id="1">item 1</div>
|
||||||
|
<div class="item" data-id="2">item 2</div>
|
||||||
|
<div class="item" data-id="3">item 3</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="msg"></div>
|
||||||
|
<script>
|
||||||
|
//第一组
|
||||||
|
const g1 = document.getElementById('g1');
|
||||||
|
const ops1 = {
|
||||||
|
animation: 166,
|
||||||
|
draggable: ".item",
|
||||||
|
dataIdAttr: "data-id",
|
||||||
|
inEnd(evnt) {
|
||||||
|
console.log(evnt)
|
||||||
|
const arr = sortable.toArray()
|
||||||
|
console.log(arr)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const sortable1 = Sortable.create(g1, ops1);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
15
temp.js
15
temp.js
|
@ -1,19 +1,16 @@
|
||||||
var g1 = document.getElementById('g1');
|
var g1 = document.getElementById('g1');
|
||||||
var ops1 = {
|
var ops1 = {
|
||||||
animation: 1000,
|
animation: 1000,
|
||||||
delay: 30,
|
//指定可以拖动的元素
|
||||||
draggable: '.item',
|
draggable: ".item",
|
||||||
//被禁止拖动的元素,第二个元素不允许被拖动
|
//************* 拖动后的数据 **********
|
||||||
filter: function (evt, item) {
|
dataIdAttr: "data-id",
|
||||||
if (item.dataset.id == '2') return true;
|
//************* 获取拖动结束的数据 **********
|
||||||
return false;
|
|
||||||
},
|
|
||||||
//拖动结束
|
|
||||||
onEnd: function (evt) {
|
onEnd: function (evt) {
|
||||||
console.log(evt);
|
console.log(evt);
|
||||||
//获取拖动后的排序
|
//获取拖动后的排序
|
||||||
var arr = sortable1.toArray();
|
var arr = sortable1.toArray();
|
||||||
document.getElementById('msg').innerHTML = 'A组排序结果:' + JSON.stringify(arr);
|
document.getElementById("msg").innerHTML = "A组排序结果:" + JSON.stringify(arr);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var sortable1 = Sortable.create(g1, ops1);
|
var sortable1 = Sortable.create(g1, ops1);
|
Loading…
Reference in New Issue