forwards和both看不出任何区别,老师麻烦改一下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>2-5</title>
<style type="text/css">
div {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
box-sizing: border-box;
width: 400px;
height: 400px;
margin: auto;
border: 1px solid red;
border-bottom: 200px solid red;
border-radius: 50%;
transform-origin: 50% 50%;
-webkit-animation-name:rotate ;
-o-animation-name: rotate;
animation-name:rotate ;
animation-duration: 3s;
animation-timing-function: linear;
/*此处写代码*/
/* animation-direction: alternate;
animation-iteration-count: infinite;*/
animation-fill-mode: forwards;
}
div:before {
content: "";
display: block;
width: 199px;
height: 199px;
box-sizing: border-box;
/*变成圆*/
border-radius: 50%;
background: white;
position: absolute;
top: 99px;
/*留 19*4的空间做圆心*/
border:80px solid red;
}
div:after {
content: "";
display: block;
width: 199px;
height: 199px;
box-sizing: border-box;
border-radius: 50%;
/*圆心颜色*/
background: red;
position: absolute;
top: 99px;
left:199px;
/*留 19*4的空间做圆心*/
border:80px solid white;
}
div:hover {
animation-play-state: paused;
}
@keyframes rotate{
from {transform: rotate(0deg);}
to {transform: rotate(180deg);}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
正在回答 回答被采纳积分+1
同学你好,关于你的问题,回答如下:
1、both是在动画开始之前,保持为第一帧状态,在动画结束后,保持为最后一帧的状态,是指开始前与结束后的状态都有设置。
2、forwards是指当动画完成后,保持最后一个属性值(在最后一个关键帧中定义),是指结束时候那一帧是什么样子的,就保持什么样子的。
3、而这里只看到了结束的状态所以是效果是一样的。开始又都是不旋转,所以看不出来效果。老师这里写了个例子,可以参考下,在第一帧改变下颜色,会发现动画开始前both已经应用这个颜色了,而forwards还没有,例:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> div { width: 100px; height: 100px; background: blue; margin-top: 20px; animation: circle 2s linear 5s; } .box1 { animation-fill-mode: forwards; } .box2 { animation-fill-mode: both; } @keyframes circle { 0% { -webkit-transform: translateX(-50px); background:red; } 50% { -webkit-transform: translateX(0px); } 100% { -webkit-transform: translateX(500px); background:#000; } } </style> </head> <body> <div class="box"></div> <div class="box1"></div> <div class="box2"></div> </body> </html>
如果我的回答帮助了你,欢迎采纳,祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星