So, I'm looking to get the size of a text string in Raphael, and I can't do it. Although the documentation states that
.attr('width');
is an option ... and I cannot set the width.
Here is FIDDLE
This is what I tried ... plus other rough ways (even using jQuery)
var page = Raphael("drawing_board");
start = function () {
this.ox = this.attr("x");
this.oy = this.attr("y");
this.attr({opacity: .5});
console.log( this.attr('width') );
},
move = function (dx, dy) {
nowX = Math.min(600, this.ox + dx);
nowY = Math.min(400, this.oy + dy);
nowX = Math.max(0, nowX);
nowY = Math.max(0, nowY);
this.attr({x: nowX, y: nowY });
},
up = function () {
this.attr({opacity: 1});
};
page.text(200, 50, "TEXT 1").attr({ cursor: "move", 'font-size': 16 , fill: '#3D6AA2'}).drag(move, start, up);
page.text(200, 200, "TEXT 2").attr({ cursor: "move", 'font-size': 16 , fill: '#3D6AA2'}).drag(move, start, up);
Maybe I need to use something other than
this.attr('width' : 30);
this.attr('width');
source
share