views:

10

answers:

1

this is my code :

<style type="text/css">
#draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; 
    border:1px solid #DDDDDD;
    color:#333333;
    background:#F2F2F2;
    }
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; 
    border:1px solid #E78F08;
    color:#FFFFFF;
    font-weight:bold;
    background:#F6A828;
    }
#droppable.highlight{
    background:#FFE45C;
    }
</style>



<div class="demo" style="margin-left:35%;margin-top:10%;cursor:pointer;">
    <div id="draggable">
        <p>Drag me to my target</p>
    </div>
    <div id="droppable" >
        <p>Drop here</p>
    </div>
</div><!-- End demo -->

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8rc3.custom.min.js"></script>
<script type="text/javascript">
$(function() {
    $("#draggable").draggable();
    $("#droppable").droppable({
        drop: function(event, ui) {
            $(this).addClass('highlight').find('p').html('Dropped!');
            $(this).append(ui.draggable.draggable( "destroy" ))
        }
    });

});

i want to drag a div into another one

and when i drag stoped , it show :

alt text

this is not seem to "into" the droppable div ,

because the draggable div be added some css style automatically when use ".draggable()"

element.style  {
left:133px;
position:relative;
top:38px;
}

i can clean the css , but does jquery-ui has a method to do this ?

thanks

A: 

Not quite sure what you want to accomplish - a bit more details would help but here is a shot...

So here is an example that 'inserts' the drag into the drop - the css is applied to the helper not the element.

$("#draggable").draggable({
    revert: 'invalid',
    helper: 'clone', 
    zIndex: 350, 
    start:  function() { $(this).toggle(); }, 
    stop:   function() { $(this).toggle(); } 
});
$("#droppable").droppable({
    accept: '#draggable',
    drop: function(event, ui) {
                $(this).addClass('highlight').find('p').html('Dropped!');
                $(ui.draggable).draggable("destroy").appendTo($(this));
    }
});
  • edit - Dived into this a bit deeper, and the reason my posted code works as opposed to the question's is because of the "helper:clone" option in the draggable. When a helper is used, it applies the left/top css to the helper, not to the actual element we are dragging.

The start/stop toggles in the draggable make the original element disappear, but turns it back on when its dropped - to simulate the default visual of $().draggable().

Also, I would be careful of the floats you have in your css - that may also give odd results.

WSkid