RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 809296
Accepted
YourDeveloper
YourDeveloper
Asked:2020-04-04 16:29:47 +0000 UTC2020-04-04 16:29:47 +0000 UTC 2020-04-04 16:29:47 +0000 UTC

虚线 svg 线动画

  • 772

面对一个有趣的问题,是否可以为给定的行从头到尾制作动画?

我寻找解决方案,有一种解决方案是在另一条线之上绘制一条线,并且断点处的第二条线与该部分具有相同的背景,结果就像一个虚线,但我有一个渐变背景,并且我应该怎么办?

在此处输入图像描述

html
  • 3 3 个回答
  • 10 Views

3 个回答

  • Voted
  1. Best Answer
    Alexandr_TT
    2020-04-04T17:16:32Z2020-04-04T17:16:32Z

    SVG 解决方案

    该解决方案是自适应的,适用于除 IE、Edge 之外的所有现代浏览器;

    #rect1 {
    fill:url(#Grad1);
    }
    #str{
    stroke-dasharray:10 20;
    stroke-dashoffset:900px; 
    fill:none;
    stroke:white;
    stroke-width:4;
    }
    <svg xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%"  viewBox="0 0 1920 715"> 
    <defs>
    <linearGradient id="Grad1"  gradientUnits="userSpaceOnUse">
            <stop offset="0%" stop-color="#00ADB3" />
    		 <stop offset="100%" stop-color="#01CEAD" />
          </linearGradient>
    </defs>
    	
    <rect id="rect1" width="100%" height="100%"   />
    <path id="str" d="m227.3 703.4c0 0 100.3-73.4 157.7-95.1 64.7-24.4 135.1-32.9 204.1-37.1 65.7-4 131.4 14.8 197.1 11.6 59.4-2.9 122.5-2.4 176.3-27.8 43.1-20.4 70.9-63.7 106.7-95.1 33.8-29.6 32.3-50 102-88.1 44.4-24.3 97.8-32.9 148.4-32.5 55.3 0.5 110.7 11.7 162.3-11.6 44-19.9 86.7-44.6 122.9-76.5 32.2-28.3 50.7-69.5 81.2-99.7 24.6-24.4 50.2-49.3 81.2-64.9 35-17.6 113.6-30.2 113.6-30.2l0 0">
    <animate attributeName="stroke-dashoffset" values="900;0" dur="5s" repeatCount="indefinite" />
    </path>
    </svg> 

    • 5
  2. Alexandr_TT
    2020-04-04T18:58:33Z2020-04-04T18:58:33Z

    CSS 解决方案

    Path与 SVG 解决方案相同,因为 CSS 还没有绘制曲线的能力。但是动画是用规则实现的CSS

    #rect1 {
    fill:url(#Grad1);
    }
    #str{
    stroke-dasharray:10 20;
    stroke-dashoffset:900px; 
    fill:none;
    stroke:white;
    stroke-width:4;
    animation: dash 8s forwards infinite;
    }
    @keyframes dash {
      0% { 
        stroke-dashoffset: 900px;
      }
       50% { 
        stroke-dashoffset: 450px;
      }
      
      100% {
        stroke-dashoffset: 0px;
      }
    }
     
    <svg xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%"  viewBox="0 0 1920 715"> 
    <defs>
    <linearGradient id="Grad1"  gradientUnits="userSpaceOnUse">
            <stop offset="0%" stop-color="#00ADB3" />
    		 <stop offset="100%" stop-color="#01CEAD" />
          </linearGradient>
    </defs>
    	
    <rect id="rect1" width="100%" height="100%"   />
    <path id="str" d="m227.3 703.4c0 0 100.3-73.4 157.7-95.1 64.7-24.4 135.1-32.9 204.1-37.1 65.7-4 131.4 14.8 197.1 11.6 59.4-2.9 122.5-2.4 176.3-27.8 43.1-20.4 70.9-63.7 106.7-95.1 33.8-29.6 32.3-50 102-88.1 44.4-24.3 97.8-32.9 148.4-32.5 55.3 0.5 110.7 11.7 162.3-11.6 44-19.9 86.7-44.6 122.9-76.5 32.2-28.3 50.7-69.5 81.2-99.7 24.6-24.4 50.2-49.3 81.2-64.9 35-17.6 113.6-30.2 113.6-30.2l0 0">
    </path>
    </svg> 

    • 4
  3. Дмитрий Мирошниченко
    2020-04-04T16:47:19Z2020-04-04T16:47:19Z

    尝试为stroke-dashoffset. 您可以在这里尝试一个示例。

    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5