jQuery升级后JS功能坏了

时间:2018-10-06 20:45:26

标签: javascript

我有一个功能,可以在SVG上绘制项目,并在文本标签下放置背景。在急需升级到最新的jQuery后,该函数的第二部分(node.insert ...)中断,抛出错误:NS_ERROR_FAILURE

function highlighted_label(node, txt, padding)
{
    if( !padding )
        padding = { horizontal: 3, vertical: 2 };

    node.append("svg:text")
        .attr("dominant-baseline", "middle")
        // IE 9 doesn't support dominant-baseline, so shift the text manually
        // Opera dosen't seem to support even y/dy ...
        .attr("y", $ && $.browser.msie && parseInt($.browser.version, 10) < 10 ? 4 : 0)
        .attr("text-anchor", "start")
        .text(typeof txt === "function" ? function(d, i) { return txt.call(this, d, i) } : txt)
    ;

    // we need to add highlight background after text was appended so we can get text dimensions,
    // but we also need to insert the background before text so it will be drawn under the text
    node.insert("svg:rect", "text")
        .attr("width", function(d) { return this.nextSibling.getBBox().width + 2 * padding.horizontal; })
        .attr("height", function(d) { return this.nextSibling.getBBox().height + 2 * padding.vertical; })
        .attr("x", function(d) { return this.nextSibling.getBBox().x - padding.horizontal; })
        .attr("y", function(d) { return this.nextSibling.getBBox().y - padding.vertical; })
        .attr("rx", 2)
    ;
}

如果我将宽度,高度,x和y替换为数值,则可以使用,但是显然我需要动态生成这些值。我尝试将nextSibling更改为nextNode和nextElementSibling,但无济于事。

我想念什么?

0 个答案:

没有答案