我正在阅读文档,但似乎找不到以下问题的答案...
我想在项目中的mask
元素上添加circle
属性,但如果可以的话,我想避免使用circle.setAttribute()
。
<!-- HTML -->
<circle />
/* JS */
let node = document.querySelector(`circle`);
circle.id = `foo`;
circle.mask = `url(#bar)`; // This isn't valid...?
circle.setAttribute(`mask`, `url(#bar)`); // What I want to avoid doing. But substitutes the invalid line above.
/* Resulting HTML after JS fires */
<circle id="foo" mask="url(#bar)" />
SVG元素上mask
的属性访问器是什么?是否存在?
mask是一个映射的CSS属性,因此您可以通过circle.style.mask = ...对其进行设置,这不会为您提供特定的属性,但是它是不使用setAttribute就可以得到的最接近的属性。