在jQuery/JavaScript中,有没有办法确定字符串的像素长度?
发布于 2016-08-23 07:03:46
如果使用Snap.svg,则可以执行以下操作:
var tPaper = Snap(300, 300);
var tLabelText = tPaper.text(100, 100, "label text");
var tWidth = tLabelText.getBBox().width; // the width of the text in pixels.
tLabelText.attr({ x : 150 - (tWidth/2)}); // now it's centered in xhttps://stackoverflow.com/questions/2057682
复制相似问题