animation - 单击矩形时使用 svg 动画降低矩形的不透明度
问题描述
单击矩形时,我需要更改矩形的不透明度(从 1 到 0)。这是我使用的代码。但我无法更改矩形的不透明度。如果有人知道请帮助我。
<svg height="800px" width="1100px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="rect1" x="263" y="87.5" width="100" height="25" fill="#F67F33" style="stroke:black;stroke-width:1">
<animate xlink:href="#rect1" attributeName="opacity" from="1" to="0" begin="click" fill="freeze" />
</rect>
</svg>
解决方案
您没有动画的持续时间。此外,如果 animate 是元素的子元素,则应用于不需要 xlink:href。
<svg height="800px" width="1100px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="263" y="87.5" width="100" height="25" fill="#F67F33" style="stroke:black;stroke-width:1">
<animate attributeName="opacity" from="1" to="0" dur="3s" begin="click" fill="freeze" />
</rect>
</svg>
如果希望动画是瞬时的,可以使用 set
<svg height="800px" width="1100px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="263" y="87.5" width="100" height="25" fill="#F67F33" style="stroke:black;stroke-width:1">
<set attributeName="opacity" to="0" begin="click" fill="freeze" />
</rect>
</svg>
推荐阅读
- html - 使用 TweenMax 缩放滚动时,文本上的图像重叠
- sql-server - 使用 Pandas 将 Pandas 数据帧附加到 Microsoft SQL 表时出现 UnicodeDecodeError
- python - requests.Response.text 显示奇数符号
- sql - SQL Server 表名姓氏
- javascript - 在 c# 中添加 html 和 javascript 函数但在 asp 页面中看起来不同并且不起作用
- three.js - 如何在three.js中实现UV坐标动画?
- r - Rmarkdown循环针织中的ggplot不起作用
- python - 使用另一个数据框选择一个数据框?
- python-3.x - 如何在 Tkinter Python Notebook 选项卡中换行文本并保持 Tkinter Notebook 选项卡的宽度不变
- apache-flink - 没有 ./bin/flink 的保存点