Raphael.js中带有transform()方法的可拖动路径

问题描述 投票:0回答:1

我正在尝试使用不推荐使用的方法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() {
     }
);

任何想法?

javascript path drag-and-drop raphael
1个回答
1
投票

我找到了解决方案!

只需使用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() {
     }
);

并且效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.