jquery下降后,在可拖动区域内丢弃div棒

时间:2011-10-13 15:42:33

标签: jquery jquery-ui

以下代码来自demo http://www.jqueryui.com/demos/droppable/

#draggable删除到#droppable之后是否有可能我无法将其移至#draggable之外,因此它始终位于#draggable内且只有我可以将其移入#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 -->

感谢您的帮助

修改 抱歉,我找到了解决方案:http://jqueryui.com/demos/droppable/#revert

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

添加

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

http://jqueryui.com/draggable/#constrain-movement 包含设置可以拖入的区域的边距。