svg+描边动画实现霓虹灯特效

参考博客:https://juejin.cn/post/6844903815708164110

效果图:

在这里插入图片描述

代码实现

html:

		 <svg width="1600px" height="100%" xmlns="http://www.w3.org/2000/svg"><!--xmlns命名空间,和html分离-->
            <symbol id="text">
              <text x="0" y="35%" class="text">youyunxia是最棒的~~</text>
            </symbol>
            <g>
              <use xlink:href="#text" class="use-text"></use>
              <use xlink:href="#text" class="use-text"></use>
              <use xlink:href="#text" class="use-text"></use>
              <use xlink:href="#text" class="use-text"></use>
              <use xlink:href="#text" class="use-text"></use>
            </g>
          </svg>

css:

	svg{
      position: absolute;
      background-color: #000;
    }
    .use-text{
      fill: none;
      stroke: white;
      stroke-dashoffset: 35%;
      stroke-dasharray: 0 87.5%;
      stroke-width: 2px;
    }
    .use-text:nth-child(1) {
      stroke: #360745;
      animation: animation1 8s infinite ease-in-out forwards;

    }

    .use-text:nth-child(2) {
      stroke: #D61C59;
      animation: animation2 8s infinite ease-in-out forwards;

    }

    .use-text:nth-child(3) {
      stroke: #E7D84B;
      animation: animation3 8s infinite ease-in-out forwards;

    }

    .use-text:nth-child(4) {
      stroke: #EFEAC5;
      animation: animation4 8s infinite ease-in-out forwards;

    }

    .use-text:nth-child(5) {
      stroke: #1B8798;
      animation: animation5 8s infinite ease-in-out forwards;
    }

    @keyframes animation1 {
      50%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 7%;
      }
      70%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 7%;
      }
    }
    @keyframes animation2 {
      50%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 14%;
      }
      70%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 14%;
      }
    }
    @keyframes animation3 {
      50%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 21%;
      }
      70%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 21%;
      }
    }
    @keyframes animation4 {
      50%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 28%;
      }
      70%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 28%;
      }
    }
    @keyframes animation5 {
      50%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 35%;
      }
      70%{
        stroke-dasharray: 7% 28%;
        stroke-dashoffset: 35%;
      }
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值