JQuery - Duplicating drag and drop object

When I drag my proposed item the clone helper is dragged and the original object is left in its place, but cannot be dragged again after. I need to be able to drag the same object twice.How can I do this?

$('.drag').draggable({
helper: 'clone',
snap: '.drop',
grid: [60, 60],
revert: function(droppable) {
    if (droppable === false) {
        return true;
    }
    else {
        return false;
    }
}
});

 $('.drop').droppable({
     drop: function(event, ui) {
        ui.draggable.fadeOut(1000);
     }
});

$('.drag').hover(
  function() {
    $(this).stop().animate({
    opacity: "0.8"
    });
}, function() {
    $(this).stop().animate({
        opacity: "1"
    });
});

$('.drop').droppable({
    drop: function(event, ui) {
        if (ui.draggable[10, 10].id) {
            $(this).append($(ui.helper).clone().draggable());
        }
    }
});

Answers


Here is a jsfiddle of the working code:

http://jsfiddle.net/qfywP/2/

The problem was with this line:

$(this).append($(ui.helper).clone().draggable())

You should first clone the helper, append it to the DOM, and then make it draggable:

ui.helper.clone().appendTo($(this)).draggable()

You should also be aware that your code was wrapped in an if statement if (ui.draggable[10, 10].id) {} . This wasn't returning true, and so your code was never being executed.

I also did some spring cleaning of your code, as you had some redundancies. $('.drop').droppable() was being declared twice, when you only needed it once.


Need Your Help

How to change color of intersected parts of CAShapeLayer in Objective-C?

iphone objective-c ios graphics cashapelayer

I am trying to draw CGPaths using CAShapeLayer. I want to change the color of the parts where lines are intersected.

Looking for Mongoose "hello world" example

javascript mongodb mongoose

Update: Been some time. But back then decided not to use Mongoose. Main reason being that we couldn't really come up with a great reason for using an ORM when using mongo and javascript.