svg实现不规则渐变流线

重点: 流线是圆的一条半径, 圆的颜色为径向渐变,  此渐变圆是svg的path的遮罩

<!DOCTYPE html>

<html>

<body style="margin-top: -300px">

    <svg className='dv-svg-container' width=1086 height="838">

        <defs>

            <path id="path" 

                d="M 17 541.89C 17 541.89 -1 620.89 7 644.89C 33 646.89 155 672.89 189 711.89C 200 746.89 155 804.89 415 823.89C 544 827.89 1053 626.89 1053 626.89"

                fill='transparent' />



            <radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">

                <stop offset="0%" style="stop-color:red;stop-opacity:1" />

                <stop offset="20%" style="stop-color:red;stop-opacity:.9" />

                <stop offset="100%" style="stop-color:red;stop-opacity:0" />

            </radialGradient>



            <mask id="mask">

                <circle id="circle" cx='0' cy='0' r='120' fill='url(#grad1)'>

                    <animateMotion dur='4'

                        path="M 17 541.89C 17 541.89 -1 620.89 7 644.89C 33 646.89 155 672.89 189 711.89C 200 746.89 155 804.89 415 823.89C 544 827.89 1053 626.89 1053 626.89"

                        rotate='auto' repeatCount='indefinite' />

                </circle>

            </mask>

        </defs>

        <use href='#path' stroke="rgba(0, 0, 0, .1)" strokeWidth='1'>

        </use>

          <use href='#path' stroke="red" mask='url(#mask)' stroke-width="4">

            <animate attributeName='stroke-dasharray' from='0, 1250' to='1250, 0' dur='4s' repeatCount='indefinite' />

        </use>

 </svg>

</body>

</html>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现SVG CSS动画的流光线效果,可以结合使用stroke-dasharray和stroke-dashoffset这两个属性。首先,为折线元素添加动画效果的class,设置stroke-dasharray的值为折线的总长度,然后通过改变stroke-dashoffset的值来实现流动效果。具体的步骤如下: 1. 在SVG中创建折线元素,并为其设置class属性以便添加动画效果。 2. 使用CSS样式为折线元素设置stroke颜色、宽度等属性,并添加animation属性来指定动画的名称、持续时间和循环方式。 3. 使用stroke-dasharray属性设置折线的总长度,可以根据实际需求调整该值。 4. 使用stroke-dashoffset属性设置折线的偏移量,初始值为折线的总长度,这样折线会完全隐藏起来。 5. 创建一个@keyframes规则,定义动画的关键帧。在关键帧中使用stroke-dashoffset属性来逐渐改变折线的偏移量,从而实现流动效果。 6. 将@keyframes规则与折线元素的动画属性关联起来,使动画生效。 下面是一个示例的代码片段,演示了如何实现SVG CSS动画的流光线效果: ```html <svg> <polyline class="flowing-line" points="50,50 200,50 200,200 50,200" /> </svg> <style> .flowing-line { stroke: #E5DA40; fill: transparent; stroke-width: 2; stroke-linecap: round; animation: flow 3s linear infinite; } @keyframes flow { 0% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -800; } } </style> ``` 希望这个回答能够帮助到您!如果您有其他相关问题,请随时提出。 相关问题: 1. 如何改变流光线的颜色和宽度? 2. 怎样调整流光线的速度和流动方向? 3. 能否在同一个SVG中同时应用多个流光线效果?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值