【问题标题】:Jquery: Draggable sensibilityJquery:可拖动的敏感性
【发布时间】:2016-12-30 23:49:54
【问题描述】:

我有一个使用 jquery 的可拖动 DOM 元素。

如果客户端在没有移动的情况下单击它,则不会调用可拖动开始,并且它的行为就像它不是可拖动的一样。

当客户端单击它并将鼠标移开 1 像素并按住不放时,拖动开始。触发事件,应用类等...

有没有办法仅在客户端单击元素并将鼠标移动至少 10 像素时才触发拖动开始?

注意:这与滚动无关。

来自https://jqueryui.com/draggable/ 现场演示的代码示例:

<style>#draggable { width: 150px; height: 150px; padding: 0.5em; }</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>

<script>
$(function(){
    $("#draggable").draggable(); 
    //goal is to only starts dragging if mouse moved more than 10px
});
</script>

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

【问题讨论】:

标签: javascript jquery jquery-ui jquery-ui-draggable


【解决方案1】:

您似乎想使用“距离”属性。 http://api.jqueryui.com/draggable/#option-distance

“鼠标按下后鼠标在开始拖动之前必须移动的距离(以像素为单位)。此选项可用于防止在单击元素时发生不必要的拖动。”

$( "#draggable" ).draggable({
  distance: 10
});

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-08
    • 2013-04-04
    相关资源
    最近更新 更多