1.less
* {
margin: 0;
padding: 0;
#wrap {
position: absolute;
width: 600px;
height: 600px;
background: url(../img/my-logo-2.png) repeat;
background-size: 50px;
border: 1px solid #000000;
border-radius: 50%;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -300px;
&:hover #wrap-inner{
//animation-play-state:动画执行的运行/暂停,默认值running,pause暂停
animation-play-state: paused;
}
#wrap-inner {
position: absolute;
width: 300px;
height: 300px;
background: tomato;
border: 2px solid white;
border-radius: 50%;
box-shadow: 2px 2px 5px tomato;
font: 30px/300px "微软雅黑";
text-align: center;
color: white;
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -150px;
animation-name: rotated;
animation-duration: 1.5s;
//animation-timing-function: linear;
animation-timing-function: cubic-bezier(.12,1.36,.65,-0.28);
//direction:normal(from→to)reverse反转(to→from)、alternate(from→to→from...循环)/alternate-reverse
animation-direction: alternate;
animation-iteration-count: 6;
//延迟为外部动画
animation-delay: 1s;
/*元素在动画外的状态: from之前to之后
1. backwards与from一致=动画开始的动作,结束回归原位
2. forwards与to一致=动画结束的动作,结束不回归原位
3. both=动画开始/结束的动作,开始/结束不回归原位
*/
//animation-fill-mode: backwards;
//animation-fill-mode: forwards;
animation-fill-mode: both;
}
}
@keyframes rotated {
from {
//Y轴:x+100px
transform: translateY(100px);
}
to {
//Y轴:x-100px
transform: translateY(-100px);
}
}
}
2.css
* {
margin: 0;
padding: 0;
}
* #wrap {
position: absolute;
width: 600px;
height: 600px;
background: url(../img/my-logo-2.png) repeat;
background-size: 50px;
border: 1px solid #000000;
border-radius: 50%;
top: 50%;
left: 50%;
margin-left: -300px;
margin-top: -300px;
}
* #wrap:hover #wrap-inner {
animation-play-state: paused;
}
* #wrap #wrap-inner {
position: absolute;
width: 300px;
height: 300px;
background: tomato;
border: 2px solid white;
border-radius: 50%;
box-shadow: 2px 2px 5px tomato;
font: 30px/300px "微软雅黑";
text-align: center;
color: white;
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -150px;
animation-name: rotated;
animation-duration: 1.5s;
animation-timing-function: cubic-bezier(0.12, 1.36, 0.65, -0.28);
animation-direction: alternate;
animation-iteration-count: 6;
animation-delay: 1s;
/*元素在动画外的状态: from之前to之后
1. backwards与from一致=动画开始的动作,结束回归原位
2. forwards与to一致=动画结束的动作,结束不回归原位
3. both=动画开始/结束的动作,开始/结束不回归原位
*/
animation-fill-mode: both;
}
@keyframes rotated {
from {
transform: translateY(100px);
}
to {
transform: translateY(-100px);
}
}
3.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>动画模式@keyframes{}</title>
</head>
<body>
<div id="wrap">
<div id="wrap-inner">cevent</div>
</div>
</body>
<link rel="stylesheet" href="css/less034.css" />
</html>
4.效果图