[英]Change svg text's vertical position using svg.js
I have read the documentation but have no clue how to achieve that. 我已经阅读了文档,但不知道如何实现。 There is no change in
dy
. dy
没有变化。
/**
* Draws text
*
* @param {String} $text Text
* @param {int} $x Starting point X coordinate
* @param {int} $y Starting point Y coordinate
* @param {Object} $font Font properties
* @returns {text} SVG JS text object
*/
drawText = function($text, $x, $y, $font) {
$svgText = $svg.text(($text !== undefined && $text !== null) ? $text : '-').attr({x: $x, y: $y}).font($font);
return $svgText.tspan.dy('0.9em');
};
Thanks a lot in advance 提前谢谢
I think your problem lies here: 我认为您的问题出在这里:
return $svgText.tspan.dy('0.9em');
On a text element tspan
is a method, not a reference: http://documentup.com/wout/svg.js#text/tspan 在文本元素上,
tspan
是一种方法,而不是引用: http : //documentup.com/wout/svg.js#text/tspan
UPDATE: 更新:
The tspan()
method does not return a tspan already present in the text element, it creates a new one. tspan()
方法不返回文本元素中已经存在的tspan,而是创建一个新的tspan。 What you are looking for is the lines
reference. 您正在寻找的是
lines
参考。 Lines holds all the tspans inside the text element. 行将所有tspan保留在text元素内。 Because
lines
is an instance of SVG.Set
, you can call the dy
method directly on it: 因为
lines
是SVG.Set
的实例, SVG.Set
可以直接在其上调用dy
方法:
text.lines.dy(0.9)
If you want to change the dy
of the first element you can use the each
method: 如果要更改第一个元素的
dy
,可以使用each
方法:
text.lines.each(function(i) {
if (i == 0)
this.dy(0.9)
})
Note that the leading
method might be useful here too: http://documentup.com/wout/svg.js#text/leading 请注意,
leading
方法在这里也可能有用: http : //documentup.com/wout/svg.js#text/leading
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.