html - 笔画动画,如何将另一条路径附加到出现的笔画?

标签 html css animation svg

我有以下动画:

@keyframes dash {
  to {
    stroke-dashoffset: 0;
  }
}

#currency-chart-path {
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  animation: dash 30s linear forwards;
}
<svg id="city-total-v2" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">
<g id="Chartline">
  <path id="currency-chart-path" stroke="#7C0A67" stroke-width="3px" fill="none" d="M443,439 L464,435 487,421 511,416 532,424 552,408 572,414 591,413 606,419" />
	<path id="chart-arrow" fill="#7C0A67" d="M604.4,423.5l6.88-2.26l-2.44-3.3c-0.1-0.22-0.25-0.41-0.43-0.58l0.01,0.02l-0.02-0.02
		c0,0,0,0.01,0.01,0.01l-2.48-3.36l-0.08,0.42l-0.27,1.66l-0.03-0.01l-0.68,3.8l0.09,0.04L604.4,423.5z"/>
</g>
</svg>


运行代码片段 看动画。

我想将箭头附加到笔划上,使其看起来像沿着路径。

这怎么可能?

最佳答案

一个想法是在做翻译的同时以相反的方向运行动画

@keyframes dash {
  to {
    stroke-dasharray: 190;
  }
}

@keyframes move {
  to {
    transform: translateX(0);
  }
}

#currency-chart-path {
  stroke-dasharray: 279;
  stroke-dashoffset: 381;
  animation: dash 10s linear forwards;
}

#Chartline {
  animation: move 10s linear forwards;
  transform: translateX(-200px);
}
<svg id="city-total-v2" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="300 300 400 400">
<g id="Chartline">
  <path id="currency-chart-path" stroke="#7C0A67" stroke-width="3px" fill="none" d="M443,439 L464,435 487,421 511,416 532,424 552,408 572,414 591,413 606,419" />
	<path id="chart-arrow" fill="#7C0A67" d="M604.4,423.5l6.88-2.26l-2.44-3.3c-0.1-0.22-0.25-0.41-0.43-0.58l0.01,0.02l-0.02-0.02
		c0,0,0,0.01,0.01,0.01l-2.48-3.36l-0.08,0.42l-0.27,1.66l-0.03-0.01l-0.68,3.8l0.09,0.04L604.4,423.5z"/>
</g>
</svg>

关于html - 笔画动画,如何将另一条路径附加到出现的笔画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53738351/

相关文章:

html - CSS 中左浮动 div 的负右边距有什么用?

javascript - 如何使用 CSS 将过渡应用到下一张幻灯片

ios - 附加导航栏在模态转场推送中从顶部滑动

javascript - 如何在有人单击音频标签中的播放按钮之前执行功能

javascript - 数据未发布..帮助! html、js、firebase

css - 在sass中正确记录h1...h6

jquery - 如何仅在另一个动画完成时才开始播放?

javascript - 使用 JQuery 更改 DIV 中的 javascript 变量

javascript - jQuery .css() 不起作用

html - 如何对齐多个 float 元素