当旋转或缩放改变时,在Raphaeljs中拖动路径
Drag paths in Raphaeljs when rotation or scale is changed
我有一个关于Raphael JS库(版本2.0.0)和拖动路径的能力的问题。我让拖动函数与我的路径一起工作,但是当我改变路径的比例或旋转时,拖动函数失去了所有控制,我的元素到处飞。
我已经尝试使用拖拽库,但我可以看到它不支持拉斐尔2.0.0,因此我不能使用它,因为我在我的代码中使用Catmull-Rom曲线,这是拉斐尔2.0.0的新功能。
任何帮助都将非常感激!下面是我的代码:
paper = Raphael(document.getElementById("holder"), 768, 1024);
var startPath = function () {
this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");
this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
},
movePath = function (dx, dy) {
var trans_x = (dx)-this.ox;
var trans_y = (dy)-this.oy;
this.translate(trans_x,trans_y);
this.ox = dx;
this.oy = dy;
},
upPath = function () {
// nothing special
};
drawing = "M152.854,210.137c-9.438-64.471,22.989-102.26,124.838-96.551s244.094,41.985,152.664,151.667C338.926,374.934,162.761,277.813,152.854,210.137z";
shape = paper.path(drawing);;
shape.translate(0,0);
shape.scale(1,1);
shape.attr({
'stroke': '#000000',
'fill': 'blue',
'stroke-width': '5',
});
shape.drag(movePath, startPath, upPath);
所以,这是工作的,但一旦我添加,例如下面的代码,它不工作:
shape.scale(2,2);
shape.rotate(90);
Raphael 2.0使用SVG矩阵,translate方法只将translate添加到当前矩阵中。您应该考虑使用绝对坐标,例如:
movePath = 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;
}
也许this.attr("x")和this.attr("cx")也是一个矩阵转换点,然后你需要使用:
获得绝对值x = this.matrix.e;
y = this.matrix.f
相关文章:
- 调整窗口大小时,可拖动的对象会出现在容器外部
- 删除对HTML元素的拖动
- jQuery UI可排序-多连接列表拖动
- 禁用SVG拖动
- 旋转后拖动对象
- JQuery UI可拖动潜水与滚动棒到鼠标
- jsPlumb-拖动克隆而不进行复制
- 当我在节点上拖动鼠标时,我如何防止使用d3.ehavior.zoom().on(“缩放”,重绘)
- 如何使元素在可拖动元素内可单击
- 如何在使用Kinetic拖动同一对象后,在旋转动画中保持先前的偏移
- 在d3中拖动一条线
- 使元素在iframe中可拖动
- 通过拖动可以更改三维模型对象在Three.js场景中的位置
- 如何使所有绘制的(矩形、圆形、直线、多边形)都可拖动?纯JS
- RaphaelJS中的文本元素不会在触摸设备上拖动
- RaphaelJS:当图像脱离帧时停止拖动
- 当旋转或缩放改变时,在Raphaeljs中拖动路径
- Raphaeljs的克隆和拖动
- RaphaelJS/Snap.SVG拖动事件
- RaphaelJS上的可拖动字体