我想在可排序占位符中显示可排序元素位置(或索引)。它在拖动第一个元素时起作用,而不是与其他元素一起使用(位置 0 而不是 1)。
请查看:http: //jsfiddle.net/upsidown/Hw2rJ/
我究竟做错了什么?
我想在可排序占位符中显示可排序元素位置(或索引)。它在拖动第一个元素时起作用,而不是与其他元素一起使用(位置 0 而不是 1)。
请查看:http: //jsfiddle.net/upsidown/Hw2rJ/
我究竟做错了什么?
我正在寻找类似挑战的解决方案,并找到了这个http://forum.jquery.com/topic/sortable-show-placeholders-position-and-give-it-a-number并稍作调整(和更正) 得到它的工作
$('.elements-sortable').sortable({
placeholder: 'sortable-placeholder',
opacity: 0.6,
helper: 'clone',
sort: function(event,ui){
$(ui.placeholder).html(Number($('.elements-sortable > div:visible').index(ui.placeholder)+1));
}
});
可能是因为它在您拖动元素之前附加了新元素
所以让我们试试这段代码
var position;
$(".elements-sortable").sortable({
placeholder: "sortable-placeholder",
opacity: "0.6",
start: function(event, ui) {
position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
$(".sortable-placeholder").html('Drop me at position ' + position);
},
change: function(event, ui) {
position = position = Number($(".elements-sortable > div:not(.ui-sortable-helper)").index(ui.placeholder)+1);
$(".sortable-placeholder").html('Drop me at position ' + position);
}
});
我已经在jsFiddle上测试过了
在jsFiddle上试试这个
$(".connectedSortable").sortable({
connectWith: ".connectedSortable",
stop: function (e,ui ) {
$("body").append("<p> current position : " + $(ui.item).prevAll().length + "</p>");
}
});