Jquery draggable(),clone()追加div ...请小提琴我的jsfiddle

n00*_*eed 11 jquery jquery-ui

更新:

http://jsfiddle.net/wJUHF/7/
这是任何可能阅读此内容的人的更新和工作小提琴.


我试图让这个小伙子工作.

这就是问题所在.我可以将图像拖到容器中.它附加一个克隆,没有问题.当我单击以将克隆的图像拖动到容器中时,它第一次正常工作.我第二次点击拖动,它不会拖动但克隆已经克隆的图像.为了更好地理解,我创建了一个jsfiddle.请看看,让我知道我在哪里错了.

http://jsfiddle.net/wJUHF/

谢谢

码:

$(function(){  
    //Make every clone image unique.  
    var counts = [0];  
    $(".dragImg").draggable({
        helper: "clone",
        //Create counter
        start: function() { counts[0]++; }
    });

    $("#dropHere").droppable({
        drop: function(e, ui){
            $(this).append($(ui.helper).clone());
            //Pointing to the dragImg class in dropHere and add new class.
            $("#dropHere .dragImg").addClass("item-"+counts[0]);
            //Remove the current class (ui-draggable and dragImg)
            $("#dropHere .item-"+counts[0]).removeClass("dragImg ui-draggable ui-draggable-dragging");
            //not working 100%           
            $(".item-"+counts[0]).dblclick(function(){
                $(this).remove();
            });     

            //make the div draggable --- Not working???    
            make_draggable($(".item-1"));              
        }
    });

    var zIndex = 0;
    function make_draggable(elements)
    {   
        elements.draggable({
            containment:'parent',
            start:function(e,ui){ ui.helper.css('z-index',++zIndex); },
            stop:function(e,ui){}
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<body>
    <div class="dragImg"><img src="http://placehold.it/80x80">
     </div>
    <div id="dropHere"></div>
</body>
Run Code Online (Sandbox Code Playgroud)

CSS:

#dropHere {
    width:400px;
    height: 400px;
    border: dotted 1px black;
}
Run Code Online (Sandbox Code Playgroud)

Vai*_*ool 5

jQuery(".dragImg").draggable({
        //  use a helper-clone that is append to 'body' so is not 'contained' by a pane
        helper: function() {
            return jQuery(this).clone().appendTo('body').css({
                'zIndex': 5
            });
        },
        cursor: 'move',
        containment: "document"
    });
Run Code Online (Sandbox Code Playgroud)

解决了您的问题 JSFIDDLE 演示


cag*_*ler 4

您只需要一个条件来区分放置处理程序:

if(ui.draggable.hasClass("dragImg"))
     $(this).append($(ui.helper).clone());
Run Code Online (Sandbox Code Playgroud)