我正在尝试使用不推荐使用的方法Element.transform()
拖动路径。这是使用不推荐使用的方法Element.translate()
的答案:
Making paths and images draggable in Raphael js
[当我简单地将translate()
替换为transform()
时,我的路径很快回到了初始位置:
drag(function (dx, dy) {
var trans_x = dx - this.ox;
var trans_y = dy - this.oy;
this.transform("t" + trans_x + "," + trans_y);
this.ox = dx;
this.oy = dy;
},
function () {
this.ox = 0;
this.oy = 0;
},
function() {
}
);
任何想法?
我找到了解决方案!
只需使用transform()的附加语法,即.transform(“ ... t” + .. + ...)
这是我的最终结果:
drag(function (dx, dy) {
var trans_x = dx - this.ox;
var trans_y = dy - this.oy;
this.transform("...t" + trans_x + "," + trans_y); //Just change this line
this.ox = dx;
this.oy = dy;
},
function () {
this.ox = 0;
this.oy = 0;
},
function() {
}
);
并且效果很好。