【问题标题】:Specifying when to drag a draggable div指定何时拖动可拖动 div
【发布时间】:2011-08-06 17:05:47
【问题描述】:

是否可以使一个 div 可拖动,并说只有当用户单击该 div 中的特定元素时才应该拖动该 div?我有一个带有标题元素的可拖动 div。我希望仅在单击元素时才进行拖动。

这是我使 div 可拖动的 javascript。

<script>
$(function() {
    $( "#edit" ).resizable();
    $( "#edit" ).draggable();
});
</script>

这是 div 的 HTML

<div class="demo">

<div id="edit" style="position:absolute; width: 250px; height: 550px;" class="comdiv">
    <h3 class="comhdr ui-widget-header">Sample</h3>

        <p id="heading" class="editableText ui-widget-content">Text for edits.</p> 

</div>

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

http://jsbin.com/awihej/2/edit

【问题讨论】:

标签: javascript jquery draggable


【解决方案1】:

您可以使用handle 选项:

$("#edit").draggable({
    handle: "h3"
});

或许:

$("#edit").draggable({
    handle: ".ui-widget-header"
});

【讨论】:

    猜你喜欢
    • 2021-06-13
    • 2021-05-11
    • 2012-03-09
    • 2017-04-18
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    相关资源
    最近更新 更多