jQuery draggable(),clone()追加div ...请拨弄我的jsfiddle [英] Jquery draggable(), clone() to append div...Pls Fiddle my jsfiddle

查看:54
本文介绍了jQuery draggable(),clone()追加div ...请拨弄我的jsfiddle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

http://jsfiddle.net/wJUHF/7/
对于任何可能阅读此书的人来说,这都是最新的工作提琴.


http://jsfiddle.net/wJUHF/7/
This is the updated and working fiddle for anyone that may read this.


我正试图让这个小提琴正常工作.

I am trying to get this jfiddle to work.

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

here is where the problem lies. I can drag the image to the container. It appends a clone, with no problem. When I click to drag the cloned image in the container it works properly the first time. The second time I click to drag, it doesnt drag but clones the already cloned image. To better understand, I have created a jsfiddle. please have a look and let me know where I am going wrong here.

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){}
        });
    }
});

HTML:

<body>
    <div class="dragImg"><img src="http://placehold.it/80x80">
     </div>
    <div id="dropHere"></div>
</body>

CSS:

#dropHere {
    width:400px;
    height: 400px;
    border: dotted 1px black;
}

推荐答案

您只需要一个条件就可以在放置处理程序中进行区分:

You just need a conditional to differentiate in the drop handler:

if(ui.draggable.hasClass("dragImg"))
     $(this).append($(ui.helper).clone());

这篇关于jQuery draggable(),clone()追加div ...请拨弄我的jsfiddle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆