gpt4 book ai didi

javascript - Chrome 不适用于线性渐变的属性偏移动画

转载 作者:技术小花猫 更新时间:2023-10-29 11:49:27 25 4
gpt4 key购买 nike

下面是在 Firefox 中运行良好的代码,但在 Chrome 中对线性渐变的偏移属性进行动画处理的任何尝试都以失败告终。

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50%" height="50%" viewBox="0 0 900 900" >

<defs>
<linearGradient id="bgg" x1="0" y1="0" x2="900" y2="900" gradientUnits="userSpaceOnUse">

<stop offset="0%" stop-color="dodgerblue"/>
<stop offset="52%" stop-color="white">
<animate
attributeName="offset"
values="100%;0%;100%"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
<stop offset="100%" stop-color="gold">
<animate
attributeName="offset"
values="100%;50%;100%"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
</linearGradient>
</defs>

<rect x="50" y="50" width="50%" height="50%" rx="5%" fill="url(#bgg)" />
</svg>

还尝试使用 gradientUnits ="objectBoundingBox "

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50%" height="50%" viewBox="0 0 900 900" >

<defs>
<linearGradient id="bgg" x1="0%" y1="0%" x2="100%" y2="100%" gradientUnits="objectBoundingBox">

<stop offset="0%" stop-color="dodgerblue"/>
<stop offset="52%" stop-color="white">
<animate
attributeName="offset"
values="100%;0%;100%"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
<stop offset="100%" stop-color="gold">
<animate
attributeName="offset"
values="100%;50%;100%"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
</linearGradient>
</defs>

<rect x="50" y="50" width="50%" height="50%" rx="5%" fill="url(#bgg)" />
</svg>

此问题的任何解决方案都将使用:SVGcssjavascript

最佳答案

对此的一种解决方案是使用 float 而不是百分比,即 values="1;0;1" 而不是 values="100%;0%;100%"

svg{border:1px solid}
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50%" height="50%" viewBox="0 0 900 900" >

<defs>
<linearGradient id="bgg" x1="0" y1="0" x2="50%" y2="50%" gradientUnits="userSpaceOnUse">

<stop offset="0" stop-color="dodgerblue"/>
<stop offset=".52" stop-color="white">
<animate
attributeName="offset"
values="1;0;1"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
<stop offset="1" stop-color="gold">
<animate
attributeName="offset"
values="1;.5;1"
dur="4s"
repeatCount="indefinite">
</animate>
</stop>
</linearGradient>
</defs>

<rect x="50" y="50" width="50%" height="50%" rx="5%" fill="url(#bgg)" />
</svg>

关于javascript - Chrome 不适用于线性渐变的属性偏移动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57131153/

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