jQuery UI Draggable - connectToSortable without helper clone - or how to move items from one list to another

妖精的绣舞 提交于 2019-11-30 10:39:00

I've been struggling with this same problem. If I do indeed set the helper to 'original' I get all kinds of jumpy and weird behavior.

Not sure if it will serve your purposes, but I wrote some code to listen to the drag start/stop events and also the sortable update event.

On drag start the item is hidden from the list. If the item is not transferred to the other list (determined by a boolean) then the item is unhidden. However, if the item is transferred then the original is removed.

$(function() {
var transferred = false;
$('#draggable li').draggable({
    connectToSortable: '#sortable',
    helper: 'clone',
    start: function(event, ui)
    {
        $(this).hide();
    },
    stop: function(event, ui)
    {
        if(!transferred)
            $(this).show();
        else
        {
            $(this).remove();
            transferred = false;
        }
    }
});

$('#sortable').sortable({
    receive: function(event, ui)
    {
        transferred = true;
    }
});

}); ​

Modified jsfiddle example. (http://jsfiddle.net/xD2dW/12/)

Obviously the code can be modified to meet your specific needs, but I hope this is at least a good start.

helper: function(){ //Do Something; }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!