【问题标题】:how to stop drag event on double click in jquery如何在jquery中双击停止拖动事件
【发布时间】:2017-03-12 14:49:09
【问题描述】:

目前我正在使用 jquery 可拖动函数 https://jqueryui.com/draggable/ 。

$( ".myclass").draggable({ });

但我想在用户双击拖动元素时停止拖动事件。这个怎么做 ?。 [可以停止单击拖动吗?由于某种原因,我的拖动元素带有鼠标指针,我无法停止拖动。

谢谢。

【问题讨论】:

  • 我很困惑。按住鼠标左键拖动。当您松开鼠标按钮时,元素停止被拖动???
  • 你能否解释一下,双击/单击它们应该如何影响拖动行为?

标签: javascript jquery jquery-ui drag-and-drop draggable


【解决方案1】:

当您释放鼠标时,Draggable 应该会自动停止。

HTML

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

JS

$( function() {
    $( "#draggable" ).draggable({
      scroll: false,
      drag: function( event, ui ) {
        $('#position').html(
          'Left : ' + ui.position.left + '<br/>' +
          'Top : ' + ui.position.top
        );
      },
      start: function( event, ui ) {
        $('#event').html("Dragging");
      },
      stop: function( event, ui ) {
        $('#event').html("Stopped");
      }
    });
  } );

试试上面的示例。每次您松开鼠标拖动时,都会自动调用 dragstop 事件。尝试在您的代码中应用此功能,以进一步调查您的案例中未调用 dragstop 的原因。

http://codepen.io/jyloo/pen/mrZmjO

【讨论】:

  • 好的。我对这个答案投了赞成票。但是朋友你能告诉我如何在双击时停止拖动。
  • 也许你想试试这个:$( document ).dblclick(function() { $( ".your-selector" ).draggable( "disable" ); $( ".your-selector" ).draggable( "enable" ); });
  • 嗨,你能检查一下这个问题吗stackoverflow.com/questions/40342500/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
  • 1970-01-01
  • 2017-08-23
  • 1970-01-01
  • 2012-04-03
相关资源
最近更新 更多