从一个列表拖动到另一个列表时,jQueryUI会更改背景颜色

Joh*_*ohn 6 html css jquery jquery-ui

我使用jQueryUI可排序,我有两个列表:

  • 添加了dvds
  • 删除了dvds

当从添加拖动到删除时,我希望div .container背景颜色变为红色.

然后当从删除拖动到添加时,我希望div .containerTwo背景颜色变为红色.

http://jsfiddle.net/w3vvL/

$("#gallery").sortable({
    connectWith: "#trash"
});
$("#trash").sortable({
   connectWith: "#gallery"
});
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢

Arc*_*rus 5

您可以使用receive事件来响应列表收到项目的时间:

查看更新的小提琴:http://jsfiddle.net/w3vvL/39/

$("#gallery").sortable({
    connectWith: "#trash",
    receive: function(event, ui) {
                    $(".container").css("background-color", "red");
            }
});
Run Code Online (Sandbox Code Playgroud)

并使用动画:

$("#gallery").sortable({
    connectWith: "#trash",
    receive: function(event, ui) {
                    $(".container").css("background-color", "green");
                    $(".container").stop().animate({ backgroundColor: "white" }, "slow");
            }
});
Run Code Online (Sandbox Code Playgroud)

查看更新的小提琴:http://jsfiddle.net/w3vvL/43/