向后转动动画CSS

时间:2014-03-31 14:54:44

标签: html css animation

在我的小测试html页面上,我有4个元素。这些元素在悬停时会播放CSS动画,但我希望当用户停留在它们上方时动画会反转。

-webkit-animation-direction:alternate;

没有工作。我目前的代码如下:

<style>

div:hover{
-webkit-animation: animationFrames ease 1s;
-webkit-animation-iteration-count: 1;
-webkit-transform-origin: 0% 0%;
-webkit-animation-fill-mode:forwards; /*Chrome 16+, Safari 4+*/ 
-webkit-animation-direction:alternate;
}

@-webkit-keyframes animationFrames {
0% {

opacity:1;
-webkit-transform:  rotate(0deg) scaleX(1) scaleY(1) ;
}
20% {
-webkit-transform:  rotate(60deg) ;

}
40% {
-webkit-transform:  rotate(40deg) ;

}
60% {
-webkit-transform:  rotate(54deg) ;
}
80% {
-webkit-transform:  rotate(42deg) ;

}
100% {

opacity:1;
-webkit-transform:  rotate(46deg) scaleX(1) scaleY(1) ;
}
}

.testje1
{
background: black;
width:48px;
height:20px;

position:absolute;
left:200px;
top:200px;
}

.testje2
{
background: black;
width:48px;
height:20px;


position:absolute;
left:300px;
top:200px;
}

.testje3
{
background: black;
width:48px;
height:20px;


position:absolute;
left:400px;
top:200px;
}

.testje4
{
background: black;
width:48px;
height:20px;

position:absolute;
left:500px;
top:200px;
}

p
{
position:absolute;
top:-14;
left:2;
color:white;
}
</style>

<a href="http://www.redrumbureau.com" target="_blank" >
<div class="testje1"><p>home</p></div>
</a>

<a href="http://www.redrumbureau.com/work" target="_blank">
<div class="testje2"><p>home</p></div>
</a>

<a href="http://www.redrumbureau.com/clients" target="_blank">
<div class="testje3"><p>clients</p></div>
</a>

<a href="http://www.redrumbureau.com/about" target="_blank">
<div class="testje4"><p>about</p></div>
</a>

非常感谢所有人的帮助!

1 个答案:

答案 0 :(得分:3)

使用reverse让动画“向后”:

-webkit-animation-direction:reverse;

如果您想了解有关可用选项的更多信息,请参阅CSS技巧的keyframes详细教程。