css3之animation属性

css3之animation

animation,是css属性中的简写,它主要有六种动画属性设置,下面简单介绍。

主要包括以下六种:

  • animation-name
  • animation-duration
  • animation-timing-function
  • animation-delay
  • animation-iteration-count
  • animation-direction

基本语法:

animation:name duration timing-function delay iteration-count direction;

下面进行分别介绍:

animation-name规定需要绑定到选择器的keyframe名称
animation-duration规定动画需要完成的时间,一般以秒或是毫秒来计数
animation-timing-function规定动画的速度曲线
animation-delay规定在动画开始时的延迟时间
animation-iteration-count规定动画的播放次数
animation-direction规定是否轮流反向播放动画

了解到以上的用法,我简单介绍一下,@keyframe。

@keyframes 规则用于创建动画。在 @keyframes 中规定某项 CSS 样式,就能创建由当前样式逐渐改为新样式的动画效果。
谈到@keyframe创建动画了,我们考虑一下浏览器的兼容问题,这就是有时候发现我们的动画在某一个浏览器中无法看到其变化。


Internet Explorer 10、Firefox 以及 Opera 支持 @keyframes 规则和 animation 属性。

Chrome 和 Safari 需要前缀 -webkit-。

注释:Internet Explorer 9,以及更早的版本,不支持 @keyframe 规则或 animation 属性。

下面,我们用一个简单实例来演示一下animation的用法和规范。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>animation动画篇</title>
		<style type="text/css">
			.content
			{
				width: 100px;
				height: 100px;
				background: #FFA500;
				animation: myanimation 3s 2;
				-webkit-animation: myanimation 3s 2 true;
				-moz-animation: myanimation 3s 2 true;
				position: relative;
			}
			@-moz-keyframes myanimation
			{
				from{left: 100px;top:0px;background-color: aqua;}
				to{left: 200px;top: 100px;background-color: bisque;}
			}
			@-webkit-keyframes myanimation
			{
				from{left: 100px;top: 0px;background-color: aqua;}
				to{left: 200px;top: 100px;background-color: bisque;}
			}
		</style>
	</head>
	<body>
		<div class="content">
			
		</div>
	</body>
</html>

动画演示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值