The animation-direction
property controls how to play the animation: in reverse
or on alternate
cycles.
animation-direction: normal|reverse|alternate|alternate-reverse;
animation-direction |
4.0 -webkit- | 10.0 | 16.0 (5.0 -moz-) | 4.0 -webkit- | 15.0 -webkit- (12.0 -o-) |
<!DOCTYPE html>
<html>
<head>
<style>
div {<!-- w ww. ja va 2s . c om-->
width: 100px;
height: 100px;
background: black;
position: relative;
-webkit-animation: myfirst 5s infinite; /* Chrome, Safari, Opera */
-webkit-animation-direction: alternate; /* Chrome, Safari, Opera */
animation: myfirst 5s infinite;
animation-direction: alternate;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes myfirst {
0% {background: red; left: 0px; top: 0px;}
25% {background: yellow; left: 200px; top: 0px;}
50% {background: blue; left: 200px; top: 200px;}
75% {background: white; left: 0px; top: 200px;}
100% {background: red; left: 0px; top: 0px;}
}
@keyframes myfirst {
0% {background: red; left: 0px; top: 0px;}
25% {background: yellow; left: 200px; top: 0px;}
50% {background: blue; left: 200px; top: 200px;}
75% {background: white; left: 0px; top: 200px;}
100% {background: red; left: 0px; top: 0px;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>