动画

1. animation-name

  • 定义动画名称
  • 格式:animatio-name: move;

2. animation-duration

  • 规定动画时长
  • 格式:animation-duration: 3s;

3. animation-timing-function

  • 规定动画如何完成一个周期
  • 格式:animation-timing-function: ease;
linear 动画从头到尾的速度是相同的。
ease 默认。动画以低速开始,然后加快,在结束前变慢。
ease-in 动画以低速开始。
ease-out 动画以低速结束。
ease-in-out 动画以低速开始和结束。

4. animation-delay

  • 规定动画在启动前的延迟时间
  • 格式:animation-delay: 3s;

5. animation-iteration-count

  • 规定动画播放次数
  • 格式:animation-iteration-count: 3;
  • infinite属性值:无限次播放

6. animation-direction

  • 规定是否应该轮流反向播放动画,如果动画被设置为只播放一次,该属性将不起作用
  • 格式:animation-direction: normal;
描述
normal 默认值。动画按正常播放。
reverse 动画反向播放。
alternate 动画在奇数次(1、3、5...)正向播放,在偶数次(2、4、6...)反向播放。
alternate-reverse 动画在奇数次(1、3、5...)反向播放,在偶数次(2、4、6...)正向播放。

7. animation-play-state

  • 规定动画是否正在运行或已暂停
  • 格式:animation-play-state: running(默认值);
  • paused属性值:指定暂停动画;running属性值:指定正在运行动画;

8. animation-fill-mode

  • 规定当动画不播放时(当动画完成时,或当动画有一个延迟未开始播放时),要应用到元素的样式
  • 格式:animation-fill-mode: both;
描述
none 默认值。动画在动画执行之前和之后不会应用任何样式到目标元素。
forwards 在动画结束后(由 animation-iteration-count 决定),动画将应用该属性值。
backwards 动画将应用在 animation-delay 定义期间启动动画的第一次迭代的关键帧中定义的属性值。这些都是 from 关键帧中的值(当 animation-direction 为 "normal" 或 "alternate" 时)或 to 关键帧中的值(当 animation-direction 为 "reverse" 或 "alternate-reverse" 时)。
both 动画遵循 forwards 和 backwards 的规则。也就是说,动画会在两个方向上扩展动画属性。
示例:
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		.box1{
			width: 600px;
			height: 600px;
			border: 1px solid #000;
			margin: 100px auto;

		}
		.box2{
			width: 100px;
			height: 100px;
			background-color: #f00;

			/*定义动画的名称*/
			animation-name: move;
			/*定义动画的执行时间*/
			animation-duration: 3s;
			/*定义动画的过渡效果*/
			animation-timing-function: linear;
			/*定义动画的延迟时间*/
			animation-delay: 2s;
			/*定义动画的执行次数(支持数字和infinite无限次)*/
			animation-iteration-count: infinite;
			/*定义动画是否反向播放*/
			animation-direction: alternate;
			/*定义动画当前是否播放*/
			animation-play-state: running;

			/*定义动画
			forwards 表示在动画完成后继续使用最后一个关键帧里面的样式。
			backwards 表示在动画开始之前使用初始关键帧里面定义的样式。
			both 同时应用forwards和backwards的效果。
			*/
			animation-fill-mode: both;
		}
		.box1:hover .box2{
			animation-play-state: paused;
		}
		@keyframes move{
			0%{
				transform: translate(0px,0px) rotateZ(0deg);
				background-color: #000;
			}
			25%{
				transform: translate(500px,0px) rotateZ(1000deg);
				background-color: #0f0;
			}
			50%{
				transform: translate(500px,500px) rotateZ(2000deg);
				background-color: #00f;
				width: 300px;
			}
			75%{
				transform: translate(0px,500px) rotateZ(1000deg);
				background-color: #ff0;
			}
			100%{
				transform: translate(0px,0px) rotateZ(0deg);
				background-color: #0ff;
			}
		}
	</style>
</head>
<body>
	<div class="box1">
		<div class="box2">
			
		</div>
	</div>
</body>
</html>