【发布时间】:2019-06-30 16:51:37
【问题描述】:
我有一个 SVG 蒙版,我想旋转里面的元素。但是,当我尝试时,看起来整个蒙版都在旋转。
我尝试了SO post,但小提琴不起作用(图像不再显示)。 原来是这样的
发生了什么
我想要发生的事情
我只想旋转“液体”元素,但不知何故,液体元素以错误的方式旋转。
这是 SVG(带有遮罩元素):
<svg width="200px" height="200px" viewBox="0 0 200 200">
<defs>
<rect id="path-1" x="75" y="65" width="50" height="100" rx="5"></rect>
</defs>
<g id="bottle" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<rect id="bottle-lid" stroke="#916548" stroke-width="5" x="82.5" y="52.5" width="35" height="15" rx="5"></rect>
<rect id="bottle-holder" stroke="#916548" stroke-width="5" x="117.5" y="55.5" width="30" height="7" rx="3.5"></rect>
<mask id="mask-2" fill="white">
<use xlink:href="#path-1"></use>
</mask>
<g id="Mask"></g>
<rect id="bottle-liquid" fill="#3498DB" mask="url(#mask-2)" x="40" y="80" width="120" height="120"></rect>
<rect id="bottle-outline" stroke="#916548" stroke-width="5" mask="url(#mask-2)" x="77.5" y="67.5" width="45" height="95" rx="5"></rect>
</g>
</svg>
这是 JS(我使用的是 GSAP 库)
const liquid = document.querySelector("#bottle-liquid")
const tl = new TimelineMax()
tl.to(liquid, 1, {
rotation: 20
})
如何仅旋转蒙版 SVG 中的某个元素?
【问题讨论】:
标签: javascript svg rotation