【问题标题】:jQuery UI Dragged & Dropped element unable to attach draggable to?jQuery UI 拖放元素无法附加可拖动元素?
【发布时间】:2012-01-25 12:50:41
【问题描述】:

我有以下代码创建一个可拖放的元素/区域。当我将我的可拖动对象拖到可放置对象时,它会克隆它并将其保存在可放置对象中。但是我无法将可拖动功能读取到它以允许将其拖动到其他地方?我试过.on/.live 使用ui.helper/ui.draggable 作为克隆元素,更改ID。但没有运气。

$(function(){

    $('.kpp_photopop').draggable({
        containment: 'form',
        cursor: 'move',
        helper: 'clone',
        snap: true,
        snapMode: 'outer'
    });

    $('.kpp_photopop_drop').droppable({
        accept: '.kpp_photopop',
        drop: function( event, ui ) {

            // Clone
            var element = ui.helper.clone();
            $(this).append(element);

            // Remove x
            ui.helper.children('.kpp_photo_x').remove();

            // Attach draggable to clone
            $(this).children('.kpp_photopop').removeClass('ui-draggable-dragging ui-draggable').attr('style','').children('.kpp_photo_x').remove();
            $(this).children('.kpp_photopop').draggable();
        }
    });
});

【问题讨论】:

    标签: jquery jquery-ui draggable droppable


    【解决方案1】:

    看起来您移除和清理的次数比实际需要的要多,并且您正在一次重新初始化放置区域的所有子项上的可拖动对象。

    这是您要查找的内容的 jsfiddle:http://jsfiddle.net/fordlover49/wRJNe/

    请注意,我还添加了一些对偏移量的操作,这样当您附加它时,它不会跳转到位置。

    【讨论】:

      猜你喜欢
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多