Javascript 拉斐尔JS上的可拖动字体
我正在尝试使用print()拖动一些添加的文本。我发现了一些这样的帖子,但代码不起作用——我把它作为一个——在chrome上重新发布,然后文本飞出屏幕。如果我将getBBox()参数设置为false,它将在第一次拖动时工作,但在随后的拖动中,鼠标将偏移Javascript 拉斐尔JS上的可拖动字体,javascript,svg,raphael,Javascript,Svg,Raphael,我正在尝试使用print()拖动一些添加的文本。我发现了一些这样的帖子,但代码不起作用——我把它作为一个——在chrome上重新发布,然后文本飞出屏幕。如果我将getBBox()参数设置为false,它将在第一次拖动时工作,但在随后的拖动中,鼠标将偏移 var w = document.body.clientWidth, h = document.body.clientHeight, paper = Raphael(0, 0, w, h); var font = paper.g
var w = document.body.clientWidth,
h = document.body.clientHeight,
paper = Raphael(0, 0, w, h);
var font = paper.getFont("Vegur");
var text = paper.print(20,20,"my dragable text",font,50);
var start = function () {
text.oBB = text.getBBox();
},
move = function (dx, dy) {
var bb = text.getBBox(true); // Setting to false works once
text.transform('...T'+[text.oBB.x - bb.x + dx, text.oBB.y - bb.y + dy]);
},
up = function () {
};
text.drag(move, start, up);
我想出来了
var start = function() {
//get original position before any transform
var obb = this.getBBox(true);
//get position after last transform
var nbb = this.getBBox(false);
//store difference
this.ox = nbb.x - obb.x
this.oy = nbb.y - obb.y;
},
move = function(dx, dy) {
//apply difference to mouse moves
this.transform('T' + [this.ox + dx, this.oy + dy]);
},
up = function() {
};