主题
  • 默认模式
  • 浅蓝色模式
  • 淡绿色模式
  • 深夜模式

定义和用法

animation-iteration-count是 CSS 动画属性之一,用于指定动画应该播放多少次。

animation-iteration-count默认值为 1,表示动画只播放一次,负值也被视为 1。

animation-iteration-count可以使用小数作为值,表示播放部分动画(如 0.5 表示播放动画的一半)。


常用的实例

接下来通过多个实例演示animation-iteration-count属性的用法,来深化您对animation-iteration-count属性的理解。

实例代码 运行代码
复制
/* 动画播放3次 */
.element {
    animation-iteration-count: 3;
}

/* 动画无限循环 */
.element {
    animation-iteration-count: infinite;
}

/* 动画播放1.5次(第二次播放到一半停止) */
.element {
    animation-iteration-count: 1.5;
}

/* 简写形式 */
.element {
    animation: myAnimation 2s ease-in-out 0.5s 3 alternate;
    /* 等同于 animation-iteration-count: 3 */
}

CSS 语法

animation-iteration-count: n|infinite;

属性值

描述
number 动画播放的具体次数(例如:1, 2, 3.5)
infinite 动画无限循环播放
initial 设置为默认值(1)
inherit 从父元素继承该属性

浏览器支持

下表中数字注明了完全支持animation-iteration-count属性的首个浏览器版本。

带 -webkit-、-moz- 或 -o- 的数字表示使用前缀的首个版本。

Chrome 浏览器 EDGE 浏览器 Firefox 浏览器 Safari 浏览器 Opera 浏览器
43.0
4.0 -webkit-
10.0 16.0
5.0 -moz-
9.0
4.0 -webkit-
30.0
15.0 -webkit-
12.0 -o-


评论区 0
发表评论
教程介绍
CSS 参考手册全面涵盖选择器、盒模型,文本属性等,助您快速检索 CSS 使用方法。
95 章节
96 阅读
0 评论
教程目录

CSS 参考手册

CSS 属性(字母排序) CSS 属性(功能排序) CSS 浏览器支持 CSS 选择器 CSS 函数 CSS 可动画性 CSS Web安全字体 CSS 单位 CSS 颜色 CSS 颜色值

CSS 属性

align-content align-items align-self all animation animation-delay animation-direction animation-duration animation-fill-mode animation-iteration-count animation-name animation-play-state animation-timing-function aspect-ratio backdrop-filter backface-visibility background background-attachment background-blend-mode background-clip background-color background-image background-origin background-position background-position-x background-position-y background-repeat background-size block-size border border-block border-block-color border-block-end border-block-end-color border-block-end-style border-block-end-width border-block-start border-block-start-color border-block-start-style border-block-start-width border-block-style border-block-width border-bottom border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width border-collapse border-color border-end-end-radius border-end-start-radius border-image border-image-outset border-image-repeat border-image-slice border-image-source border-image-width border-inline border-inline-color border-inline-end border-inline-end-color border-inline-end-style border-inline-end-width border-inline-start border-inline-start-color border-inline-start-style border-inline-start-width border-inline-style border-inline-width border-left border-left-color border-left-style border-left-width border-radius border-right border-right-color border-right-style border-right-width border-spacing border-start-end-radius border-start-start-radius border-top-left-radius border-top-right-radius border-top-style