css动画属性

100 阅读1分钟

询问这个问题的时候会继续往下问到js如何实现动画效果

@keyframes name
  1. [animation-name] 规定需要绑定到选择器的 keyframe 名称
  2. [animation-duration] 规定完成动画所花费的时间,以秒或毫秒计。
  3. [animation-timing-function]规定动画的速度曲线。
  4. [animation-delay] 规定在动画开始之前的延迟。
  5. [animation-iteration-count]规定动画应该播放的次数。
  6. [animation-direction]规定是否应该轮流反向播放动画。
<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 100px;
  height: 100px;
  background-color: red;
  position: relative;
  animation-name: example;
  animation-duration: 4s;
}

@keyframes example {
  0%   {background-color:red; left:0px; top:0px;}
  25%  {background-color:yellow; left:200px; top:0px;}
  50%  {background-color:blue; left:200px; top:200px;}
  75%  {background-color:green; left:0px; top:200px;}
  100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>

<p><b>注释:</b>本例在 Internet Explorer 9 以及更早的版本中无效。</p>

<div></div>

</body>
</html>
transition属性
  1. transition-property: 指定CSS属性的name,transition效果
  2. transition-duration: 效果需要指定多少秒或毫秒才能完成
  3. transition-timing-function: 指定transition效果的转速曲线(这个好玩)
  4. transition-delay:定义transition效果开始的时候
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>
<style> 
div
{
	width:100px;
	height:100px;
	background:red;
	transition:width 2s;
	-webkit-transition:width 2s; /* Safari */
}

div:hover
{
	width:300px;
}
</style>
</head>
<body>
<div></div>

<p>鼠标移动到 div 元素上,查看过渡效果。</p>

</body>
</html>