【问题标题】:jquery after drop, dropped div stick inside draggable area拖放后的jquery,将div棒放在可拖动区域内
【发布时间】:2011-10-13 15:42:33
【问题描述】:

以下代码来自演示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

【问题讨论】:

  • 如果您有解决方案,请将其放在答案中并接受

标签: jquery jquery-ui


【解决方案1】:
【解决方案2】:

添加

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多