animation-iteration-count: infinite 用于让动画无限循环。需配合 @keyframes 定义动画帧,并通过 animation 属性应用到元素,如 .element { animation: example 2s infinite; }。示例中盒子每1.5秒左右移动并持续重复,常用于加载旋转、呼吸效果等UI动效。实际使用时应注意性能,避免大量复杂动画影响流畅度,可通过 Intersection Observer 在不可见时暂停以优化体验。

CSS 中的 animation-iteration-count: infinite 用于让动画无限次循环播放。它常配合 @keyframes 和其他动画属性一起使用,使元素的动画持续不断地运行。
常用写法如下:
.element {
animation-name: example;
animation-duration: 2s;
animation-iteration-count: infinite;
}也可以简写在 animation 复合属性中:
.element {
animation: example 2s infinite;
}示例:让一个 div 左右移动
立即学习“前端免费学习笔记(深入)”;
@keyframes moveSide {
0% { transform: translateX(0); }
50% { transform: translateX(100px); }
100% { transform: translateX(0); }
}
.box {
width: 50px;
height: 50px;
background: blue;
animation: moveSide 1.5s infinite;
}这个盒子会每 1.5 秒完成一次左右移动,并且不断重复。
例如做一个旋转的加载图标:
.loader {
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}以上就是css animation-iteration-count infinite如何使用的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号