Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.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_Raphael - Fatal编程技术网

Javascript 拉斐尔JS中带下划线的文本

Javascript 拉斐尔JS中带下划线的文本,javascript,raphael,Javascript,Raphael,我想做一件简单的事。只是一个带有下划线的文本,就像html中的标记一样。如何在Raphael JS中实现这一点?以下是一个函数,它应该完成您所追求的功能: function underlineText(textElement) { var textBBox = textElement.getBBox(); var textUnderline = canvas.path("M"+textBBox.x+" "+(textBBox.y+textBBox.height)+"L"+(textBBo

我想做一件简单的事。只是一个带有下划线的文本,就像html中的标记一样。如何在Raphael JS中实现这一点?

以下是一个函数,它应该完成您所追求的功能:

function underlineText(textElement) {
    var textBBox = textElement.getBBox();
var textUnderline = canvas.path("M"+textBBox.x+" "+(textBBox.y+textBBox.height)+"L"+(textBBox.x+textBBox.width)+" "+(textBBox.y+textBBox.height));  
}

var textElement = canvas.text(100,100,"hello world");
underlineText(textElement);

我认为前面的答案已经不好了(因为对我来说它根本不起作用),但通过一些技巧,我让它成为了一种魅力

这是:

var underlineText = function () {
var textBBox = textElement.getBBox();
var textUnderline = paper.path("M"+textBBox.x+" "+(textBBox.y+textBBox.height)+"L"+(textBBox.x+textBBox.width)+" "+(textBBox.y+textBBox.height));};

underlineText(textElement);
干杯


www.stefanomoscardini.it

适用于SVG画布,未使用VML进行测试(相关讨论在此仅做一个说明,如果您旋转文本,它将不会像预期的那样工作。不过,这是一个优雅的解决方案!这是唯一有效的答案!谢谢。这应该被接受
var text=paper.text(...);
if (text.node){
    $(text.node).css('text-decoration','underline');
}