gpt4 book ai didi

html - css 过渡动画不适用于 svg 路径的 "d' 属性更改

转载 作者:太空狗 更新时间:2023-10-29 14:51:05 25 4
gpt4 key购买 nike

jsFiddle

我正在尝试将 css 转换应用于 svg 各种元素。 transition: all 2s 适用于圆形,但不适用于路径。

怎么会有比“全部”更具体的东西?

编辑:

下面的链接有更多关于动画 svg 线或路径的信息...而且似乎还不能使用 css 转换...

Can you use CSS transitions on SVG attributes? Like y2 on a line?

最佳答案

Transitions 只能应用于 presentation 属性,以及一些其他属性,例如 x, y, cx,cy ...可在此处找到支持的属性列表 http://dev.w3.org/SVG/proposals/css-animation/animation-proposal.html不幸的是 d 不是其中之一......

由于跨浏览器仍然不可靠地支持它,您可以使用 SMIL 动画来获得相同的结果。

var type = true;

setInterval(function() {
$("#path").attr('from', type ? "M 0 0 L 50 100" : "M 0 0 L 100 50");
$("#path").attr('to', type ? "M 0 0 L 100 50" : "M 0 0 L 50 100");
$("#path")[0].beginElement()
$("#circle").attr('from', type ? "40" : "10");
$("#circle").attr('to', type ? "10" : "40");
$("#circle")[0].beginElement()
type = !type;
}, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<svg>
<path stroke="#000000" stroke-width="5" d="M 0 0 L 100 50" >
<animate id="path" attributeName="d" from="M 0 0 L 100 50" to="M 0 0 L 50 100" dur="1s" fill="freeze"/>
</path>
<circle fill="#0000FF" cx="10" cy="50" r="10" >
<animate id="circle" attributeName="cx" from="10" to="40" dur="1s" fill="freeze"/>
</circle>
</svg>

关于html - css 过渡动画不适用于 svg 路径的 "d' 属性更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32729752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com