【问题标题】:Droppable on drop, element gets appended twiceDroppable on drop,元素被附加两次
【发布时间】:2015-07-22 12:45:23
【问题描述】:

由于这种拖放操作,我几乎要崩溃了。我只是想在触发 drop 时提醒一条消息。

这是我的代码,我不知道为什么会发送两次警报!请帮帮我,否则我很快就会住院 :p

jQuery:

$(document).ready(function() {

    init();

    function init () {

        sorting();
        dragging();
        dropping();
    }

    function resize (event, ui) {
        ui.helper.find("img#day_image").css({ height: img_height, width: img_width });
        ui.helper.css({ height: img_height, width: img_width });
    }

    function sorting () {
        $("#dropbar").sortable({
            connectWith: ".deal-itinerary-list",
            revert: true,
            dropOnEmpty: false
            /*
            stop: function (event, ui) {

                $("li.placeholder").each(function(i) {

                    $(this).find("span.day-nr").text('Day ' + ++i);

                });

            }
            */
        });
    }

    function dragging () {
        $(".deal-itinerary-list li").draggable({
            connectToSortable: "#dropbar",
            helper: function (event) {
                var image = $(this).find("img#day_image").clone();
                return image;
            },
            revert: false,
            opacity: 0.5,
            cursorAt: { top: 50, left: 50},
            start: function (event, ui) {
                $(ui.helper.find(".day-content")).hide();
            },
            drag: resize
        });
    }

    function dropping() {

        $("#dropbar").droppable({
            tolerance: "pointer",
            accept: "img#day_image",
            drop: function (ui) {

                alert("hello");

            }
        });

    }

    $( "ul, li" ).disableSelection();

});

【问题讨论】:

    标签: javascript jquery jquery-ui-droppable


    【解决方案1】:

    如果在同一个元素上同时使用 sortable 和 droppable ,这显然是一个已知问题。

    This questions solved my problem.

    【讨论】:

      猜你喜欢
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 1970-01-01
      • 2018-05-19
      • 2016-04-08
      相关资源
      最近更新 更多