css - 完成后如何防止css3动画重置?

标签 css css-animations

<分区>

我写了一个css3动画,只执行了一次。动画效果很好,但动画结束后会重置。我怎样才能避免这种情况,我想保留结果而不是重置它。

$(function() {
  $("#fdiv").delay(1000).addClass("go");
});
#fdiv {
  width: 10px;
  height: 10px;
  position: absolute;
  margin-left: -5px;
  margin-top: -5px;
  left: 50%;
  top: 50%;
  background-color: red;
}

.go {
  -webkit-animation: spinAndZoom 1s 1;
}

@-webkit-keyframes spinAndZoom {
  0% {
    width: 10px;
    height: 10px;
    margin-left: -5px;
    margin-top: -5px;
    -webkit-transform: rotateZ(0deg);
  }
  100% {
    width: 400px;
    height: 400px;
    margin-left: -200px;
    margin-top: -200px;
    -webkit-transform: rotateZ(360deg);
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<div id="fdiv"></div>

这是 demo .

最佳答案

添加animation-fill-mode: forwards;

到你的.go

The animation’s final keyframe continues to apply after the final iteration of the animation completes.

http://css-infos.net/property/-webkit-animation-fill-mode

关于css - 完成后如何防止css3动画重置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31184626/

上一篇:javascript - 滚动到 div 的底部?

下一篇:css - Bootstrap.css 和 NVD3 的 css 好像有冲突,导致没有工具提示。我可以在我的网页上同时使用两者吗?

相关文章:

javascript - 具有透明颜色的 HTML Canvas : ctx. 笔划重新笔划行为

javascript - 如何在 svg 中给多边形渐变填充?

css - Bootstrap 中的 col-lg-*、col-md-* 和 col-sm-* 有什么区别?

ios - CSS3 fadeIn 转换在 iOS 设备上不起作用

javascript - 当 svg 在视口(viewport)中时触发动画

jquery - 如何在动画菜单的同时无缝运行超链接?

javascript - 如何使 Bootstrap 3 工具提示与文档中的显示相同

html - 如果我的图片是随机的,我该如何声明 img 的宽度和高度?

html - CSS 动画的 z-index 问题

html - 重置背景颜色 CSS