我想将一条线拖到我拖动的元素上。为此,我需要元素在拖动时的“真实”位置。
我试过这个:
textSign.drag(function (dx, dy, posx, posy) {
var myMatrix = new Snap.Matrix();
myMatrix.translate(dx,dy);
this.transform(myMatrix.toTransformString());
//drag another element
}, function(x,y,event){
//contains only mouse position
}, function(){
this.attr({x: parseFloat(this.attr("x")) + this.matrix.e, y: parseFloat(this.attr("y")) + this.matrix.f});
this.transform('t0,0');
});
我可以在移动时获得(矩阵或某物的)真实位置吗?
最佳答案
您可以通过捕获正在移动的元素的边界框,然后将属性更改为该元素来完成此操作。
所以额外的代码是...
var bb = this.getBBox();
line.attr({ x2: bb.cx, y2: bb.cy })
你也可以摆脱矩阵的东西......
关于javascript - snap.svg 拖动 "real"位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26996532/