jquery 如何在双击时停止拖动事件
how to stop drag event on double click in jquery
目前我正在使用 jquery 可拖动功能 https://jqueryui.com/draggable/。
$( ".myclass").draggable({ });
但是我想在用户双击拖动元素时停止拖动事件。这个怎么做 ?。 [是否可以单击停止拖动?由于某些原因,我的拖动元素带有鼠标指针,我无法停止拖动。
谢谢。
当您松开鼠标时,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。
目前我正在使用 jquery 可拖动功能 https://jqueryui.com/draggable/。
$( ".myclass").draggable({ });
但是我想在用户双击拖动元素时停止拖动事件。这个怎么做 ?。 [是否可以单击停止拖动?由于某些原因,我的拖动元素带有鼠标指针,我无法停止拖动。
谢谢。
当您松开鼠标时,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。