相关疑难解决方法(0)

改变动画CSS3的速度?

我有动画:

img.rotate {
  animation-name: rotate;
  animation-duration: 1.5s;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
Run Code Online (Sandbox Code Playgroud)

我有无限的旋转图像.现在我想用JS改变旋转速度.我试过了:

$('img').css('animation-duration', '2s');
Run Code Online (Sandbox Code Playgroud)

持续时间会改变速度,但动画会重新启动到帧密钥0%(第一个),但我只想让动画继续,就像什么也没发生一样; 我不想回到0%.

我怎样才能做到这一点?

css jquery css-animations

13
推荐指数
1
解决办法
2万
查看次数

如何在 CSS 中减慢悬停时的背景平移速度

我有一个 div 背景平移,我想在悬停时减慢速度:

@keyframes backgroundScroll {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}
div {
  width: 30vw;
  height: 30vh;
  background: repeating-linear-gradient(
    45deg,
    #EE0000,
    #EE0000 10px,
    #990000 10px,
    #990000 20px
  );
  background-size: 150%;
  background-position: 50% 50%;
  animation: backgroundScroll 3s linear infinite;
}
div:hover{
  animation: backgroundScroll 20s;
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)

理论上,这样的东西是可行的,但它不会保留状态。我去挖掘并发现可以保留动画状态:StackOverflow-Change Animation speed on hoover。解剖之后,我发现它使用了一种幻象,归结为我的目的就是这个。我想知道是否有办法将其应用于原始代码。

html css hover css-animations

4
推荐指数
1
解决办法
126
查看次数

标签 统计

css ×2

css-animations ×2

hover ×1

html ×1

jquery ×1