Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Raphael库通过鼠标单击或鼠标拖动在Javascript中执行动画?_Javascript_Raphael - Fatal编程技术网

如何使用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);