限制 svg 路径中​​的点数

我使用 SVG 开发了下图。我使用stroke-dasharray将点添加到路径的末尾,但是添加了多个点。如何在紫色路径的末端添加一点?是否可以使用 stroke-dasharray 做到这一点?

https://i.stack.imgur.com/fXFrO.png

这是我目前的 HTML:

<svg style="fill:none; stroke:#81125A" width="300px" height="200px">
    <linearGradient id="gradient" x1="0" y1="0" x2="0" y2="100%">
      <stop offset="0%" stop-color="#81125A" />
      <stop offset="100%" stop-color="#81125A" />
    </linearGradient>

    <path d=" M  130.45001850481378   166  A  78 78 107 0 1 126.20062143070965 96.52297197783665" stroke="#e7e7e8"></path>

    <path d=" M  131.14095054523523   86.82703015701578  A  78 78 107 0 1 189.84677986512304 49.427292161274664" stroke="#e7e7e8"></path>

    <path d=" M  200.72216074279504   49.04751549251053  A  78 78 107 0 1 261.8938594545413 82.26103796461837" stroke="#e7e7e8"></path>

    <path d=" M  267.49850888669266   91.58874102031533  A  78 78 107 0 1 266.2203371568729 164.81515037921423" stroke="#e7e7e8"></path>

    <path d=" M  130.45001850481378   166  A  78 78 107 1 1 265.5499814951862 166" id="purple" fill='none' class="purple"></path>

    <path d=" M  130.45001850481378   166  A  78 78 107 1 1 265.5499814951862 166" id="white" fill='none' class="border"></path>

    <path d=" M  130.45001850481378   166  A  78 78 107 1 1 265.5499814951862 166" id="back" fill='none' class="fill"></path>

 </svg>

这是我的 CSS:

path {
    stroke-linecap: round;
    stroke-width: 8;
  }

path.grey {
  stroke: #e7e7e8;
}

path.purple {
  stroke: url(#gradient);
  stroke-dasharray: 100,326;
  stroke-dashoffset: 100; 
  stroke-width: 8;
  animation: dash 2.6s ease-out forwards;
}

path.border {
  stroke: #81125A;
  stroke-dasharray: 0px,100px;
  stroke-dashoffset: 100px;
  stroke-width: 19.5px; 
  animation: dash 2.6s ease-out forwards;
  fill-rule: evenodd;

}

path.fill {
  stroke: #FFFFFF;
  stroke-dasharray: 0px,100px;
  stroke-dashoffset: 100;
  stroke-width:9.5px;
  animation: dash 2.6s ease-out forwards;

}

.circle{
  height:15px;
  width:15px;
  background-color:purple;
}

@keyframes dash {
  to {
    stroke-dashoffset: 1; 
  }
}
pyxiaoxiao 回答:限制 svg 路径中​​的点数

我不确定 stroke-dasharray 是否适合这里的工具。

在这里您可能正在寻找 stroke-dashoffset,它将帮助您在整个 SVG 的道路上取得一些进展。您可以使用一些 JS 获得它的长度:path.getTotalLength() 并决定您希望它进展多长时间,百分比或类似。

这篇文章可能会帮助您更好地了解它的工作原理。
https://css-tricks.com/svg-line-animation-works/

好消息是您可以制作动画!请注意,当您的进度为 0 时,Firefox 会出现一些偷偷摸摸的行为,它可能会在初始加载时倒退(如果我没记错的话)。

本文链接:https://www.f2er.com/1158727.html

大家都在问