Droppable on drop,元素被附加两次

时间:2015-07-22 12:45:23

标签: javascript jquery jquery-ui-droppable

由于这种拖累,我几乎崩溃了。我只是想在触发掉落时提醒一条消息。

这是我的代码,我无法确定为什么警报会被发送两次!请帮助我,或者我很快就会去医院: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();

});

1 个答案:

答案 0 :(得分:0)

如果在同一元素上使用了sortable和droppable,那么这是一个已知的问题。

This questions solved my problem

相关问题