Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拉斐尔JS上的可拖动字体_Javascript_Svg_Raphael - Fatal编程技术网

Javascript 拉斐尔JS上的可拖动字体

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

我正在尝试使用print()拖动一些添加的文本。我发现了一些这样的帖子,但代码不起作用——我把它作为一个——在chrome上重新发布,然后文本飞出屏幕。如果我将getBBox()参数设置为false,它将在第一次拖动时工作,但在随后的拖动中,鼠标将偏移

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() {
};