user969068
user969068

Reputation: 2943

jquery after drop, dropped div stick inside draggable area

this below code is from demo http://www.jqueryui.com/demos/droppable/

Is it possible after #draggable is dropped to #droppable I can not move it outside of #draggable, so it always stick inside #draggable and only i can move it inside #droppable?

<style>
    #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin:   10px 10px 10px 0; }
    #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
    </style>
    <script>
    $(function() {
        $( "#draggable" ).draggable();
        $( "#" ).droppable({
            drop: function( event, ui ) {
                $( this )
                    .addClass( "ui-state-highlight" )
                    .find( "p" )
                        .html( "Dropped!" );
            }
        });
    });
    </script>



<div class="demo">

<div id="draggable" class="ui-widget-content">
    <p>Drag me to my target</p>
</div>

<div id="droppable" class="ui-widget-header">
    <p>Drop here</p>
</div>

</div><!-- End demo -->



<div style="display: none;" class="demo-description">
<p>Enable any DOM element to be droppable, a target for draggable elements.</p>
</div><!-- End demo-description -->

Thanks for any help

Edit: Sorry i found the solution : http://jqueryui.com/demos/droppable/#revert

Upvotes: 1

Views: 3296

Answers (2)

Sven van den Boogaart
Sven van den Boogaart

Reputation: 12331

add

.draggable({ containment: '#droppable' })

http://jqueryui.com/draggable/#constrain-movement containment sets the margins of the area where you can drag in.

Upvotes: 0

Related Questions