Append draggable image into specific div

534 views Asked by At

i am using jquery and jquery ui to drag and scale images. Also i need to append this image to the target div.

my code:

<div id="decorations">

<div style="float:left; margin-left:5px; margin-top:5px;">
<img class="dragger" id="obj1" style="cursor: -webkit-grab;" src="objects/bike.png" width="80" height="80">
</div>

<div style="float:left; margin-left:5px; margin-top:5px;">
<img class="dragger" id="obj2" style="cursor: -webkit-grab;" src="objects/car.png" width="80" height="80">
</div>

</div>

I am trying to append the draggable image when i leave it on the div bellow:

<div id="contentHolder"></div>

The code:

<script>
$(document).ready(function() {
window.zindex = 999;
    $(".dragger").resizable({handles: 'ne, se, sw, nw'});
    $(".dragger").parent().draggable({
    $(".dragger").appendTo("#contentHolder"); //Tried this one without luck
    });
});
</script>

Also i tried this:

<script>
$(document).ready(function() {
window.zindex = 999;
    $(".dragger").resizable({handles: 'ne, se, sw, nw'});
    $(".dragger").parent().draggable({      
     accept: '.dragger',
        drop: function (event, ui) {
            $('#contentHolder').append(ui.draggable);
        }
    });
});
</script>

Thank you so much!

1

There are 1 answers

0
Mathieu Labrie Parent On BEST ANSWER

Make the contenHolder droppable :

$(".contenHolder").droppable({      
   drop: function( event, ui ) {        
       //do something here
   }    

 });