2014-03-31 73 views
0

在我的小测试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> 

所有帮助非常感谢!

+0

你尝试过'动画方向:反向;'? –

+0

对不起,我没有正确地提出我的问题。我现在要编辑它。 –

+0

编辑完成前不久,但忘了提及。抱歉! –

回答

3

使用reverse,使动画走“倒退”:

-webkit-animation-direction:reverse; 

通过CSS技巧这里有keyframes一个不错的详细教程,如果你想了解更多关于提供给您的选项。

+0

对不起,我没有正确地提出我的问题。我现在要编辑它。 –

+0

编辑完成前不久,但忘了提及。抱歉! –