sortable.js handle 指定拖拽句柄才能拖动父元素,有你拗口不好表达,我们理解成我们要拖拽item 1元素,而这个元素包含了a、b、c 三元素,我们可以通过handle属性指定按住a时才能拖动item 1元素。
属性名称 | 类型 | 说明 |
---|---|---|
handle | string | 指定class样式名称,注意要带点 handle:".move" |
代码例子
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>sortable.js handle属性例子</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;
}
#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> handle:".move" 点击A区域才能拖动</div>
<div class="item" data-id="1" onclick="del()">
<div class="move">A</div>
<div>item 1</div>
</div>
<div class="item" data-id="2" onclick="del()">
<div class="move">A</div>
<div>item 2</div>
</div>
<div class="item" data-id="3" onclick="del()">
<div class="move">A</div>
<div>item 3</div>
</div>
</div>
</div>
<div id="msg"></div>
<script>
//第一组
var g1 = document.getElementById('g1');
var ops1 = {
animation: 1000,
delay: 30,
draggable: ".item",
handle:".move",
//拖动结束
onEnd: function (evt) {
console.log(evt);
//获取拖动后的排序
var arr = sortable1.toArray();
document.getElementById("msg").innerHTML = "A组排序结果:" + JSON.stringify(arr);
},
};
function del() {
alert("执行了del事件")
}
var sortable1 = Sortable.create(g1, ops1);
</script>
</body>
</html>