使用jQuery更改CSS动画速度时遇到问题

Having Issues Changing CSS Animation Speed with jQuery

提问人:Tarık Öztürk 提问时间:11/9/2023 最后编辑:Tarık Öztürk 更新时间:11/9/2023 访问量:34

问:

我正在尝试使用 jQuery 动态更改 SVG 元素中 CSS 动画的速度,但我遇到了 SVG 在值更改时跳跃的问题。

我无法解决问题,你能帮我吗?

法典

var inputElement = document.getElementById('sp');

inputElement.addEventListener('input', function() {
  var set = inputElement.value + 's';
  $("#figure svg .sleeve").css("animation-duration", set);
});
@keyframes flow {
  0% {
    stroke-dashoffset: 55px;
  }
  100% {
    stroke-dashoffset: 0px;
  }
}

#figure svg {
  animation: fadeopacity 1s 0.5s both, flow 5s infinite linear;
}

#figure svg .sleeve {
  stroke-width: 3;
  stroke-dasharray: 50px 5px;
  fill: none;
  color: #4792da;
  stroke: currentColor;
  animation-name: flow;
  animation-duration: 1s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  transition: all 0.3s;
  animation-play-state: running;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
  <section>
    <div id="figure" class="fig">
      <svg height="50" width="800">
        <line
          class="sleeve" x1="0" y1="20" x2="800" y2="20"
          style="stroke:rgb(255,0,0);stroke-width:2"
        />
      </svg>
    </div>
  </section>
  <input type="number" id="sp" min="0,1" max="2" step="0.1" value="0.1">
</div>

javascript css-动画

评论


答: 暂无答案