如何解决getPointAtLength DOM 异常,但当 d-path 被分配 *without* 命名空间时不会
正在执行:path.getPointAtLength(0)
为什么必须使用命名空间创建 path
是否有任何逻辑。
但是必须为 d
属性指定没有命名空间?
对于所有其他属性不使用 setAttributeNS
是否所有浏览器都是安全的?
- FireFox 错误:
DOMException: SVGGeometryElement.getPointAtLength: 没有可用于测量的路径
- Chrome 错误:
DOMException:无法在“SVGGeometryElement”上执行“getPointAtLength”:元素的路径为空。
const _NAMESPACE_ = "http://www.w3.org/2000/svg";
function getPoint(label,path) {
try {
let l = path.getPointAtLength(0);
console.log(label,l.x,l.y )
} catch (e) {
console.error(label,e.stack.split("\n")[0])
}
}
// Works fine:
let P1 = document.createElementNS(_NAMESPACE_,"path");
P1.setAttribute('d',`M1 1`);
getPoint('P1',P1);
//Error: DOMException The elements's path is empty
let P2 = document.createElementNS(_NAMESPACE_,"path");
P2.setAttributeNS(_NAMESPACE_,'d',`M2 2`);
getPoint('P2',P2);
//Error: getPointAtLength is not a function
let P3 = document.createElement("path");
P3.setAttributeNS(_NAMESPACE_,`M3 3`);
getPoint('P3',P3);
//Error: getPointAtLength is not a function
let P4 = document.createElement("path");
P4.setAttribute('d',`M4 4`);
getPoint('P4',P4);
//works: namespace = null
let P5 = document.createElementNS(_NAMESPACE_,"path");
P5.setAttributeNS( null,`M5 5`);
getPoint('P5',P5);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。