简体   繁体   English

列表项的可排序和可拖动行为

[英]Sortable and draggable behavior on list items

I'm coming here because I'm having trouble doing something with jQuery UI's sortable/draggable/droppable. 我来这里是因为在使用jQuery UI的sortable / draggable / droppable时遇到麻烦。

I'm trying to do something like iTunes playlist (when you change the order of tracklist or move a track to another playlist) The idea is that I have a list of tracks (in a ) and I want this list to be sortable, and that's the easy part. 我正在尝试做类似iTunes播放列表的操作(当您更改曲目列表的顺序或将曲目移至另一个播放列表时),其想法是我有一个曲目列表(位于中),并且希望该列表可排序,并且那是容易的部分。 Indeed I also have a second list (of playlist) and I want tracks to be draggable to those "playlist" items to do something. 确实,我还有第二个列表(播放列表),并且我希望将曲目拖到那些“播放列表”项上以执行某些操作。

Here's an exemple : http://jsfiddle.net/MSGhf/1/ 这是一个示例: http : //jsfiddle.net/MSGhf/1/

(the sortable is working exactly as I want it, the black line is just a <div class="plholder"></div> ) (sortable完全按照我的要求工作,黑线只是<div class="plholder"></div>

But when you start dragging a track, sortable works fine. 但是,当您开始拖动轨道时,sortable可以正常工作。 But when you move the track out of the draggable, the new order stays, and so dragging tracks on playlist potentialy change the track list order too, which is a problem. 但是,当您将曲目移出可拖动对象时,新顺序将保持不变,因此在播放列表上拖动曲目可能也会更改曲目列表的顺序,这是一个问题。

So I don't know how to block the sortable when a track leaves it. 所以我不知道当轨道离开时如何阻止可排序对象。

If you have any idea :) 如果您有任何想法:)

Thanks ! 谢谢 !

Ah, ok, I see what's happening. 啊,好的,我知道发生了什么事。 Here's what you want to do (working example, here: http://jsfiddle.net/mori57/L3CF8/1/ ) 这就是您想要做的(示例,请参见: http : //jsfiddle.net/mori57/L3CF8/1/

    $(".droppable").droppable({
        tolerance: "pointer",
        drop:function(){
            // You need to tell your sortable to cancel 
            // the last drag/drop interaction
            $("ul").sortable("cancel");
            alert("Do something on drop ...");   
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM