14sortable.js chosenClass 选中拖拽对象的样式
This commit is contained in:
parent
e04e77f383
commit
2bd87cee7b
|
@ -0,0 +1,88 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>sortable.js chosenClass属性例子</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: 80%;
|
||||||
|
float: left;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itxst > div {
|
||||||
|
padding: 6px;
|
||||||
|
background-color: #fdfdfd;
|
||||||
|
border: solid 1px #eee;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: move;
|
||||||
|
}
|
||||||
|
|
||||||
|
.itxst .innner {
|
||||||
|
padding: 6px;
|
||||||
|
background-color: #fdfdfd;
|
||||||
|
border: solid 1px #eee;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
cursor: move;
|
||||||
|
}
|
||||||
|
|
||||||
|
#msg {
|
||||||
|
clear: both;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ghost {
|
||||||
|
background-color: red !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chosen {
|
||||||
|
border: solid 2px #3089dc !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="box">
|
||||||
|
<div id="g1" class="itxst">
|
||||||
|
<div>鼠标点击按住下面的 item 2对象1秒后再拖拽</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>
|
||||||
|
// sortable.js chosenClass 选中拖拽对象的样式
|
||||||
|
// 当设置了delay延迟属性就很容易理解这个属性了
|
||||||
|
// 比如delay延迟1秒当鼠标按住1秒后
|
||||||
|
// 才会添加chosenClass样式到选中的对象。
|
||||||
|
const g1 = document.getElementById('g1');
|
||||||
|
const msg = document.getElementById('msg');
|
||||||
|
const ops = {
|
||||||
|
animation: 166,
|
||||||
|
delay: 166,
|
||||||
|
draggable: '.item',
|
||||||
|
// 停靠样式
|
||||||
|
ghostClass: 'ghost',
|
||||||
|
// ******* 选中样式 *******
|
||||||
|
chosenClass: 'chosen',
|
||||||
|
// 禁用html5原生拖拽行为
|
||||||
|
focusFallback: true,
|
||||||
|
group: { name: 'bunny', pull: true, pull: 'clone' },
|
||||||
|
// 拖动结束
|
||||||
|
onEnd(event) {
|
||||||
|
console.log(event);
|
||||||
|
const arr = sortable.toArray();
|
||||||
|
msg.innerHTML = JSON.stringify(arr);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortable = Sortable.create(g1, ops);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
38
temp.js
38
temp.js
|
@ -1,23 +1,21 @@
|
||||||
//第一组
|
|
||||||
var g1 = document.getElementById('g1');
|
var g1 = document.getElementById('g1');
|
||||||
var ops1 = {
|
var ops1 = {
|
||||||
animation: 1000,
|
animation: 1000,
|
||||||
//指定可以拖动的元素
|
delay: 1000,
|
||||||
draggable: '.item',
|
draggable: '.item',
|
||||||
//拖动后的数据
|
//停靠位置样式
|
||||||
dataIdAttr: 'data-no',
|
ghostClass: 'ghost',
|
||||||
//停靠位置样式
|
//************* 选中样式 ***********
|
||||||
ghostClass: 'ghost',
|
chosenClass: 'chosen',
|
||||||
//************* 拖动对象移动样式
|
//禁用html5原生拖拽行为
|
||||||
dragClass: 'drag',
|
forceFallback: true,
|
||||||
//************* 禁用html5原生拖拽行为
|
group: { name: 'itxst.com', pull: true, put: true },
|
||||||
forceFallback: true,
|
//拖动结束
|
||||||
//获取拖动结束的数据
|
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