css3动画,淡入淡出?

时间:2013-06-26 14:03:54

标签: css3 animation fadein move

我正在学习如何做css3动画。我怎么能让这个盒子在向下移动时淡入呢?

示例:http://jsfiddle.net/RtWTN/1/

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
  animation: mymove 3s ease-out forwards;
  animation-iteration-count: 3;
}

@keyframes mymove
{ 
  from { top: 0px;}
  to { top: 200px;}
}
</style>
</head>
<body>


<div></div>

</body>
</html>

2 个答案:

答案 0 :(得分:4)

您可以向动画关键帧添加多个规则。

{
from {top:0px; opacity: 0;}
to {top:200px; opacity: 1;}
}

http://jsfiddle.net/T2DnG/1/

答案 1 :(得分:1)

动画 top 属性不利于浏览器性能。只需使用transform: translateY(<value>),此解决方案的性能就会大大提高。

@keyframes mymove
{
  from {transform: translateY(0); opacity: 0;}
  to { transform: translateY(200px); opacity: 1;}
}

Browsers are optimized for transforms and opacity