动画属性详解
CSS 提供多个动画相关属性,用于细致控制动画行为。通常与 @keyframes 搭配使用。
1. 常用动画属性
| 属性名 | 说明 | 示例值 |
|---|---|---|
animation-name |
指定使用的关键帧名称 | slideMove |
animation-duration |
动画持续时间 | 2s, 500ms |
animation-timing-function |
动画节奏曲线 | ease, linear, steps(4) |
animation-delay |
动画延迟时间 | 0s, 1s |
animation-iteration-count |
动画播放次数 | 1, infinite |
animation-direction |
播放方向 | normal, reverse, alternate |
animation-fill-mode |
动画执行前后状态 | none, forwards, backwards, both |
animation-play-state |
动画播放状态 | running, paused |
2. 简写属性
animation: slideMove 2s ease-in-out 0s infinite alternate;
等同于:
animation-name: slideMove;
animation-duration: 2s;
animation-timing-function: ease-in-out;
animation-delay: 0s;
animation-iteration-count: infinite;
animation-direction: alternate;
动画属性详解示例
源码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<title>CSS 动画属性详解示例</title>
<style>
.circle {
width: 80px;
height: 80px;
background-color: #42a5f5;
border-radius: 50%;
margin: 40px auto;
animation: bounce 2s ease-in-out 0s infinite alternate;
}
@keyframes bounce {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-120px);
}
}
</style>
</head>
<body>
<div class="circle"></div>
</body>
</html>
相关内容
- 什么是 CSS? CSS(层叠样式表)是一种用来描述网页外观样式的语言。它定义了如何为HTML元素设置颜色、字体、布局等视觉效果,使网页更加美观和易于阅读。
- CSS 的作用与工作原理 介绍CSS的主要作用及其工作原理,帮助理解如何通过样式表控制网页元素的外观和布局,实现内容与表现的分离。
- CSS 的引入方式 介绍CSS的三种主要引入方式:内联样式、内部样式表和外部样式表,帮助开发者选择合适的方法应用样式。
- 基本语法结构 介绍CSS的基本语法结构,包括选择器、属性和属性值的组成方式,帮助理解如何编写有效的样式规则。
- 注释的使用方式 介绍CSS中注释的写法和作用,帮助开发者在样式代码中添加说明,提高代码可读性和维护性。
- 基本选择器 介绍CSS中最基础的三种选择器:元素选择器、类选择器和ID选择器,是学习CSS样式编写的基础。