【问题标题】:snap.svg drag "real" positionsnap.svg 拖动“真实”位置
【发布时间】:2014-11-19 17:30:21
【问题描述】:

我想将一条线拖到我拖动的元素上。为此,我需要拖动时元素的“真实”位置。

我试过了:

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');
});

我可以在移动时获得(矩阵或某物的)真实位置吗?

【问题讨论】:

  • 我不清楚你在拖动时想要做什么,为什么要使用矩阵,你能把你拥有的东西放在小提琴上吗,那么它可能会更明显一点?
  • 我想将点(x2,y2) 的末端设置为对象的中心,同时拖动:jsbin.com/koheyekema/1/edit?html,js,output

标签: javascript svg snap.svg


【解决方案1】:

您可以通过抓住被移动元素的边界框来做到这一点,然后将属性更改为那个。

所以附加代码将是......

  var bb = this.getBBox();
  line.attr({ x2: bb.cx, y2: bb.cy })

jsbin

你也可以摆脱矩阵的东西......

jsbin

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-06
    • 2015-01-20
    • 2015-10-07
    • 1970-01-01
    • 2014-07-09
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多