javascript - jQuery升级后JS函数坏了
问题描述
我有一个在 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 但无济于事。
我错过了什么?
解决方案
推荐阅读
- bash - wg-quick "wait: pid 9185 is not a child if this shell" on Debian 8.11
- python - 删除 Matplotlib,Python 中某些子图的 y 轴刻度标签
- r - 如何在 R XGboost 中找到每个预测的重要变量
- python - 计算一组因变量的滚动窗口多元线性回归的有效方法?
- javascript - JavaScript 中的位运算符是否有安全的替代方案?
- php - 如何使用简码显示 Woo Commerce 评论?
- sql - 将项目加在一起但单独计算,组和子组?
- javascript - 动态创建的 DOM 未显示在组件中
- git - 子分支的 Git 拉取请求
- javascript - jquery 数据表:“未捕获的类型错误:无法读取未定义的属性‘长度’”在销毁和重新初始化后。表作为数据源