javascript 如何在javascript中捕获dragend事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15114090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to catch dragend event in javascript?
提问by Ashraf Bashir
I'm trying to catch the dragend event in Javascript for a draggable DIV. The dragend event is not fired at all, why ? and how to solve this ? PS, I'm ussing .draggable() method from: jQuery UI 1.9.2
我正在尝试在 Javascript 中为可拖动的 DIV 捕获 dragend 事件。dragend 事件根本没有被触发,为什么?以及如何解决这个问题?PS,我使用 .draggable() 方法来自:jQuery UI 1.9.2
Here's my code: http://jsfiddle.net/vBMav/
这是我的代码:http: //jsfiddle.net/vBMav/
HTML:
HTML:
<div id="divId"> ... </div>
CSS:
CSS:
#divId {
background-color: #000000;
color: #ffffff;
height: 200px;
width: 200px;
}
Javascript:
Javascript:
$('#divId').draggable();
$('#divId')
.bind('dragstart', function(){ $("#divId").text("drag start"); })
.bind('drag', function(){ $("#divId").text("dragging"); })
.bind('dragend', function(){ $("#divId").text("drag ended"); });
回答by Jacob
Try using dragstop
instead of dragend
尝试使用dragstop
代替dragend
.bind('dragstop', function(){ $("#divId").text("drag ended");});