使用 YUI 拖放时如何检测点击?

发布于 2024-07-08 12:05:34 字数 648 浏览 5 评论 0原文

我正在使用 YUI 为 div 添加拖放支持。 它还响应点击。 不幸的是,即使在拖放操作之后,单击行为也会生效。 这是一个代码片段:

// Create a DOM object for the group tag.
div = document.createElement('div');
div.className = 'group';
div.onclick = function() { beginEditName(); }
container.appendChild(div);

// Enable drag/drop for the group tag.
dragdrop = new YAHOO.util.DD(div);
dragdrop.scroll = false;
dragdrop.on('dragEvent', function(ev) { onDrag(ev); });
dragdrop.on('endDragEvent', function(ev) { onEndDrag(ev); });
dragdrop.setXConstraint(0,0);

单击应该编辑文本,而拖放应该移动标签。 但是,将触发 onclick 事件,以便在移动标签后开始文本编辑。

我可以围绕这个问题进行编码,但是有没有更直接的 YUI 方法来区分简单的单击和拖放?

I'm using YUI to add drag drop support to a div. It also responds to clicks. Unfortunately, the click behavior takes effect even after a drag drop operation. Here's a code snippet:

// Create a DOM object for the group tag.
div = document.createElement('div');
div.className = 'group';
div.onclick = function() { beginEditName(); }
container.appendChild(div);

// Enable drag/drop for the group tag.
dragdrop = new YAHOO.util.DD(div);
dragdrop.scroll = false;
dragdrop.on('dragEvent', function(ev) { onDrag(ev); });
dragdrop.on('endDragEvent', function(ev) { onEndDrag(ev); });
dragdrop.setXConstraint(0,0);

Click is supposed to edit text, while drag drop is supposed to move the tag. However, the onclick event is firing so that text editing begins after the tag is moved.

I could code around the problem, but is there a more direct YUI way of differentiating a simple click from a drag drop?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2024-07-15 12:05:34

迈克尔,

http://ericmiraglia.com/yui/demos/ddclick.php

查看来源,如果您对此有任何其他问题,请告诉我(雅虎网的 ericmiraglia)。

修改。 我将在这里复制代码,这样如果这个人从他的服务器上取下代码,人们将能够检查源代码。

var beingDragged = false;
var dd = new YAHOO.util.DD("drag");

dd.subscribe("mouseDownEvent", function(e){
    beingDragged = false;
});
dd.subscribe("startDragEvent", function(e) {
    beingDragged = true;
});
dd.subscribe("mouseUpEvent", function(e) {
    if(beingDragged) {
        alert("dragged")
    } else {
        alert("clicked");
    }
})

Michael,

http://ericmiraglia.com/yui/demos/ddclick.php

View the source, and let me know (ericmiraglia at yahoo dot com) if you have any further questions on this.

Modification. I will copy the code here, this way if this guy take off the code from his server people will be able to check the source.

var beingDragged = false;
var dd = new YAHOO.util.DD("drag");

dd.subscribe("mouseDownEvent", function(e){
    beingDragged = false;
});
dd.subscribe("startDragEvent", function(e) {
    beingDragged = true;
});
dd.subscribe("mouseUpEvent", function(e) {
    if(beingDragged) {
        alert("dragged")
    } else {
        alert("clicked");
    }
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文