3

我真的需要你的帮助。我一直在努力做到这一点,但我就是做不到..

jsfiddle:http: //jsfiddle.net/5Vyq8/13/

js代码:

$(document).ready(function () {

    // Treetable
    $("table").treetable({
        expandable: true,
        initialState: "expanded",
        expanderTemplate: "<a href='#'>&nbsp;&nbsp;&nbsp;&nbsp;</a>",
        indent: 24,
        column: 0
    });

    // Draggable
    $("table .draggable").draggable({
        opacity: .75,
        refreshPositions: true,
        revert: "invalid",
        revertDuration: 300,
        scroll: true,
        delay: 100,
        cursor: 'move'
    });

    //Droppable
    $("table tbody tr").each(function () {
        $(this).droppable({
            accept: ".draggable",
            hoverClass: "append-to-task",
            over: function (e, ui) {         

                // add class 'accept-incoming-task' to the row under after 1 second
            },
            out: function () {

            },
            drop: function (e, ui) {

                var droppedEl = ui.draggable;
                // Adds the task as the first child to dropped row
                $("table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
            },
        });
    });
});

我想要实现的是:

  1. 将一行拖到另一行(完成!)
  2. 悬停超过 1 秒时,它应该在下面的行中添加一个类
  3. 当仍然悬停并移动到其他行时,它应该删除上一步中添加的类

我感谢您的时间和帮助。

4

2 回答 2

1

看看http://jsfiddle.net/snowMonkey/7yEaU/

$("table tbody tr").each(function () {
    var that=this;
    $(this).droppable({
        accept: ".draggable",
        over: function (e, ui) { 
            // add class 'accept-incoming-task' to the row under after 1 second
            hoverTimeout = setTimeout(function(){
                $(that).addClass("append-to-task");
            }, 1000);
        },
        out: function () {
           clearTimeout(hoverTimeout);
            $(that).removeClass("append-to-task");
        },
        drop: function (e, ui) {

            var droppedEl = ui.draggable;
            // Adds the task as the first child to dropped row
            $("table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
        },
    });
});

我有你的第二步工作。您需要做的第一件事是从悬停中删除 hoverClass,您将在超时延迟后手动将其拉出。

其次,在此之外创建一个 hoverTimeout 变量(这样您就可以从悬停和输出回调中访问它)。

三、在over:回调中,设置hoverTimeout为1000ms,并在触发时添加类。

最后,在 out 回调中,清除超时并移除类。

这处理了第二步和第三步——但它不允许您将放置的项目拖放到捕手上。希望能帮助到你!

于 2013-08-02T16:56:03.237 回答
0

我终于设法解决了这个问题!这是解决方案:

$(document).ready(function () {

    // Treetable
    $("table").treetable({
        expandable: true,
        initialState: "expanded",
        expanderTemplate: "<a href='#'>&nbsp;&nbsp;&nbsp;&nbsp;</a>",
        indent: 24,
        column: 0
    });

    // Draggable
    $("table .draggable").draggable({
        opacity: .75,
        refreshPositions: true,
        revert: "invalid",
        revertDuration: 300,
        scroll: true,
        delay: 100,
        cursor: 'move'
    });

    //Droppable
    var hoverTimeout;
    $("table tbody tr").each(function () {
        var that=this;
        $(this).droppable({
            accept: ".draggable",
            hoverClass: "append-to-task",
            over: function (e, ui) { 
                clearTimeout(hoverTimeout);
                $('.accept-incoming-task').removeClass('accept-incoming-task');
                // add class 'accept-incoming-task' to the row under after 1 second
                hoverTimeout = setTimeout(function(){
                    $(that).addClass("accept-incoming-task");
                }, 1000);
            },
            out: function () {

            },
            drop: function (e, ui) {
                $('.accept-incoming-task').removeClass('accept-incoming-task');
                var droppedEl = ui.draggable;
                // Adds the task as the first child to dropped row
                $("table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
            },
        });
    });
});

小提琴:http: //jsfiddle.net/7yEaU/2/

于 2013-08-03T20:15:33.823 回答