如何在JavaScript中捕捉Dragend事件? [英] How to catch dragend event in javascript?

查看:342
本文介绍了如何在JavaScript中捕捉Dragend事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试捕获Javascript中的dragend事件以获取可拖动的DIV. dragend事件根本没有触发,为什么?以及如何解决呢? PS,我使用的是来自jQuery UI 1.9.2的.draggable()方法

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

这是我的代码: http://jsfiddle.net/vBMav/

HTML:

<div id="divId"> ... </div>

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"); });

推荐答案

尝试使用'dragstop'而不是'dragend'

Try using 'dragstop' instead of 'dragend'

.bind('dragstop',function(){$(#divId").text("drag end");});

.bind('dragstop', function(){ $("#divId").text("drag ended");});

这篇关于如何在JavaScript中捕捉Dragend事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆