如何使用Raphael库通过鼠标单击或鼠标拖动在Javascript中执行动画?
我想要的是能够用鼠标点击或拖动到想要的位置来发出这个移动的信号如何使用Raphael库通过鼠标单击或鼠标拖动在Javascript中执行动画?,javascript,raphael,Javascript,Raphael,我想要的是能够用鼠标点击或拖动到想要的位置来发出这个移动的信号 var drawingArea = Raphael(10,10,400,400); var circle = drawingArea.circle(200,200,15); circle.attr({fill:'blue', stroke:'red'}); var animation = Raphael.animation({cx:30, cy:30}, 5000); circle.animate(animation); 你可以用
var drawingArea = Raphael(10,10,400,400);
var circle = drawingArea.circle(200,200,15);
circle.attr({fill:'blue', stroke:'red'});
var animation = Raphael.animation({cx:30, cy:30}, 5000);
circle.animate(animation);
你可以用
如果要在鼠标拖动后将其拖动到所需位置,则需要操纵其坐标(而不是使用动画)。 该函数允许您为开始拖动、结束拖动和拖动时移动事件设置回调 一种方法是在开始时存储原始位置,并在移动时更新:
var start = function () {
this.ox = this.attr("cx");
this.oy = this.attr("cy");
};
var move = function (dx, dy) {
this.attr({cx: this.ox + dx, cy: this.oy + dy});
};
circle.drag(move, start);
你可以看到。嗨!你试过我发布的解决方案了吗?你有什么问题吗?
var start = function () {
this.ox = this.attr("cx");
this.oy = this.attr("cy");
};
var move = function (dx, dy) {
this.attr({cx: this.ox + dx, cy: this.oy + dy});
};
circle.drag(move, start);