【问题标题】:How to animate gradient offset using Velocity.js如何使用 Velocity.js 动画渐变偏移
【发布时间】:2015-04-29 12:17:58
【问题描述】:

我想为渐变设置动画以“向右移动”,为此我必须为停止元素的偏移属性设置动画,但现在我只成功为停止颜色属性设置动画。

<linearGradient id="gr-simple" x1="0" y1="0" x2="100%" y2="0%">
<stop id = "first"  stop-color="lightblue" offset="10%"/>
<stop id = "second" stop-color="red" offset="90%"/>
</linearGradient>

作品:

$("#first")
        .delay(1500)
        .velocity({stopColor: "#FF4E50" },{duration:1500});

不起作用:

$("#first")
        .delay(1500)
        .velocity({offset: "50%"},{duration:1500});

非常感谢我能得到的任何帮助。 谢谢

【问题讨论】:

    标签: javascript jquery-animate gradient offset velocity.js


    【解决方案1】:

    正在寻找同样的东西,偶然发现了这支笔: http://codepen.io/jorgeatgu/pen/niubs?editors=101

    诀窍似乎是使用 x1、x2、y1 和 y2 值:

                <linearGradient id="background" gradientUnits="objectBoundingBox" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop id="one" offset="0%" stop-color="crimson"/>
                <stop id="two" offset="100%" stop-color="cyan"/>
            </linearGradient>
    

    在你的 js 中:

    $("#background")
            .delay(500)
            .velocity({x2: "100%", y2: "0%" },{duration:1500, easing: "linear"})
    

    我还不知道这些属性,但你应该可以找到一些文档!

    PS : 请务必为&lt;stop&gt; 上的颜色和&lt;linearGradient&gt; 上的偏移设置动画

    希望这会有所帮助! (即使我可能为时已晚)

    洛伊克

    编辑:

    实际上我认为动画偏移应该工作,但它没有,所以我猜使用 x1/x2/y1/y2 值移动整个渐变是选项,它做了我想要的

    【讨论】:

      猜你喜欢
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 1970-01-01
      相关资源
      最近更新 更多