UPDATE:
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.
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/
Thanks
CODE:
$(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;
}
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"
});
SOLVED UR PROBLEM JSFIDDLE DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With