08sortable.js filter 过滤或忽略指定元素

This commit is contained in:
bunny 2024-01-31 16:33:34 +08:00
parent 2ece58e638
commit 77db51ef9d
2 changed files with 77 additions and 6 deletions

View File

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>sortable.js filter属性例子</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: 70%;
float: left;
margin-right: 10px;
}
.itxst>div {
padding: 6px;
background-color: #fdfdfd;
border: solid 1px #eee;
margin-bottom: 10px;
cursor: move;
}
#msg {
clear: both;
width: 100%;
}
.move {
float: left;
width: 100px;
background-color: #3a6bfd;
}
</style>
</head>
<body>
<div class="box">
<div id="g1" class="itxst">
<div> item 2 无法被拖动 class包含了filter类</div>
<div class="item" data-id="1">
item 1
</div>
<div class="item filter" 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,
delay: 30,
draggable: ".item",
filter: ".filter",
onEnd() {
const arr = sortable1.toArray();
console.log(arr)
}
};
const sortable1 = Sortable.create(g1, ops1);
</script>
</body>
</html>

11
temp.js
View File

@ -1,16 +1,15 @@
var g1 = document.getElementById('g1');
var ops1 = {
animation: 1000,
delay: 30,
draggable: '.item',
handle: '.move',
filter: '.filter',
//拖动结束
onEnd: function (evt) {
console.log(evt);
//获取拖动后的排序
var arr = sortable.toArray();
var arr = sortable1.toArray();
document.getElementById('msg').innerHTML = 'A组排序结果' + JSON.stringify(arr);
},
};
function del() {
console.log('执行了del事件');
}
var sortable = Sortable.create(g1, ops1);
var sortable1 = Sortable.create(g1, ops1);