【发布时间】:2019-12-05 19:47:36
【问题描述】:
在这个jsFiddle 中,我有一个Raphael 画布,它带有一个可以单击或拖动的矩形。
如果您将鼠标移动到矩形然后单击它,您可能会稍微移动它(文本会告诉您)。我需要在我的应用程序中处理单击并在用户打算单击时忽略拖动移动。例如,只有当它大于 5 像素时,我才需要启用拖动。如果意图只是点击,有没有办法让拉斐尔不移动矩形?
var paper = Raphael("canvas", 600, 600);
var title = this.paper.text(50, 10, 'click on the square');
var rect = this.paper.rect(20, 20, 30, 30);
rect.attr('fill', 'black')
var start = function () {
this.odx = 0;
this.ody = 0;
},
move = function (dx, dy) {
title.attr('text', 'mouse moved')
this.translate(dx - this.odx, dy - this.ody);
this.odx = dx;
this.ody = dy;
},
up = function () {};
rect.drag(move, start, up);
rect.mousedown(function(e){
title.attr('text', 'mouse down')
})
【问题讨论】:
-
您是否尝试过使用 click 而不是 mousedown ?
-
在 mousedown 和 mouseup 事件之后触发 click 事件,所以问题并没有消失,矩形会在 mouseup 之前被无意拖动。
标签: javascript raphael