首页 > web前端 > css教程 > 正文

css3中animation动画属性如何使用

清浅
发布: 2018-11-16 15:28:35
原创
3715人浏览过

css3中animation动画共有六个属性分别是动画名称,完成动画所需时间,速度,延迟,播放速度以及是否有反向播放,本篇文章将和大家详细分享有关css3中animation动画属性的方法,有一定的参考价值,希望对大家有所帮助。

CSS主要是用于描绘网页的样式和布局而CSS3 是最新的 CSS 标准,提供了更多的方法而且使用CSS3,可以创建动画,使网页内容更加丰富今天将和大家分享css3中的动画属性——animation

注意在使用过程中浏览器兼容问题

Internet Explorer 10、Firefox 以及 Opera 支持 animation 属性。

立即学习前端免费学习笔记(深入)”;

Safari 和 Chrome 支持 -webkit-animation 属性

所以在写程序的过程中应考虑到浏览器兼容问题

animation 属性

用于设置六个动画属性:

(1)animation-name:规定动画的名称。

animation-name:demo//Internet Explorer 10、Firefox 以及 Opera 浏览器中
-webkit-animation-name:demo//Safari 和 Chrome
登录后复制

(2)animation-duration:完成动画所花费的时间(以秒和毫秒为单位)

animation-duration:3s;
-webkit-animation-duration:3s;
登录后复制

(3)animation-timing-function:动画速度曲线

linear :以匀速播放 

ease :刚开始动画速度慢然后加快在结束时变慢  (默认)

ease-in :指动画以低速开始    

ease-out :指动画以低速结束。 

ease-in-out :动画以低速开始和结束

cubic-bezier(n,n,n,n) :在 cubic-bezier 函数中设置想要的值,是从 0 到 1 的数值    

animation-timing-function:ease;
-webkit-animation-timing-function:ease;
登录后复制

(4)animation-delay:动画开始延迟时间

animation-delay:3s;
-webkit-animation-delay:3s;
登录后复制

(5)animation-iteration-count:动画播放的次数

n: 自定义动画播放次数的数值

infinite :指动画无限次循环播放    

animation-iteration-count:4;//循环四次
-webkit-animation-iteration-count:infinite;//循环无数次
登录后复制

(6)animation-direction:动画是否轮流反向播放   

 normal   动画应该正常播放  (默认)

alternate    动画应该轮流反向播放    

animation-direction:normal;
-webkit-animation-direction:alternate;
登录后复制

让一个小方块按照右下左上的方向进行运动

div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:demo;
animation-iteration-count:infinite;
animation-duration:2s;
animation-timing-function:ease;
animation-delay:0.1s;
animation-direction: alternate; 
}
/* Safari and Chrome 浏览器*/
-webkit-animation:demo;/*设置动画名称*/
-webkit-animation-iteration-count:infinite;/*动画执行次数*/
-webkit-animation-duration:5s;/*动画花费时间*/
-webkit-animation-timing-function:ease;/*动画速度*/
-webkit-animation-delay:2s;/*动画延迟*/
-webkit-animation-direction: alternate; /*动画是否反向*/
}
/*设置动画运行区域*/
@keyframes demo
{
	0% {background-color: pink;left:0;top:40px;}
	25%{background-color: hotpink;left:300px;top:40px;}
	50%{background-color: yellow;left:300px;top:340px;}
	75%{background-color: blue;left:0;top:340px;}
	100%{background-color: green;left:0;top:30px;}
}
/*Safari and Chrome浏览器*/
@-webkit-keyframes demo
{
    0% {background-color: pink;left:0;top:40px;}
	25%{background-color: hotpink;left:300px;top:40px;}
	50%{background-color: yellow;left:300px;top:340px;}
	75%{background-color: blue;left:0;top:340px;}
	100%{background-color: green;left:0;top:30px;}
}
</style>
登录后复制

效果图:

GIF1.gif

总结:以上就是本篇文章的内容了,希望大家通过本篇文章能对CSS3中的animation有所了解

以上就是css3中animation动画属性如何使用的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号