我想在可排序的占位符中显示可排序元素的位置(或索引)。它在拖动第一个元素时有效,而不是与其他元素一起拖动(位置0而不是1)。
请查看:http://jsfiddle.net/upsidown/Hw2rJ/
我做错了什么?
发布于 2013-10-09 03:45:49
我正在寻找一个类似挑战的解决方案,并找到了这个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));
}
});
发布于 2012-08-03 19:47:44
可能是因为它会在拖动元素之前附加新元素
那么让我们来试试这段代码
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上测试过了
发布于 2013-12-04 14:31:15
在jsFiddle上试试这个
$(".connectedSortable").sortable({
connectWith: ".connectedSortable",
stop: function (e,ui ) {
$("body").append("<p> current position : " + $(ui.item).prevAll().length + "</p>");
}
});
https://stackoverflow.com/questions/11794854
复制相似问题