取消可排序项目的拖动 [英] Cancel dragging of a sortable item
本文介绍了取消可排序项目的拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个绝对常见的可排序情况:
An absolutely common sortable case:
<script>
$(function() {
$("#sortable").sortable();
});
</script>
<ul id="sortable">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
问题..在某些情况下需要取消对项目的拖动,并且有一个很好的建议,
Problem. Need to cancel dragging of an item on some condition and there is a good advice of Andrew Whitaker, but that approach is working only for jquery-ui-draggable and fails for sortables:
$("#sortable").sortable({
start: function() {
return false; // will still cause `this.helper is null`
}
});
将非常感谢您提供建议.
Will be greateful for suggestions.
推荐答案
sort
函数回调的排序方式与对draggable的拖动作用相同(
The sort
function callback does the same for sort as drag for draggable (demo):
$("#sortable").sortable({
sort: function() {
if ($(this).hasClass("cancel")) {
$(this).sortable("cancel");
}
}
});
这篇关于取消可排序项目的拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文