SVG元素上的遮罩的属性访问器是什么?

问题描述 投票:1回答:1

我正在阅读文档,但似乎找不到以下问题的答案...

我想在项目中的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的属性访问器是什么?是否存在?

javascript svg properties mask
1个回答
1
投票

mask是一个映射的CSS属性,因此您可以通过circle.style.mask = ...对其进行设置,这不会为您提供特定的属性,但是它是不使用setAttribute就可以得到的最接近的属性。

© www.soinside.com 2019 - 2024. All rights reserved.