700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 关于CSS3中Animation动画属性的用法解析

关于CSS3中Animation动画属性的用法解析

时间:2022-12-31 10:49:20

相关推荐

关于CSS3中Animation动画属性的用法解析

web前端|css教程

CSS3,Animation

web前端-css教程

这篇文章主要为大家详细介绍了CSS3中Animation动画属性用法,教大家如何使用animation动画,感兴趣的小伙伴们可以参考一下

站长工具箱源码,vscode怎么设置边框颜色,ubuntu 无线上网,tomcat渗透,sqlite大型,响应式网页设计布局缺点,帝国cms修改数据库,2m带宽服务器,jquery 视频插件下载,前端嵌入框架,最左爬虫,php从零,松原seo,x_springboot,dedecms 标签 函数,itool网站综合查询系统,浏览器网页图标favicon不显示,登录失败页面模板,网站后台 无法插入图片,h5页面制作源码,交友会员管理系统免费版,blh转换xyz程序下载lzw

要使用animation动画,先要熟悉一下keyframes,Keyframes的语法规则:命名是由”@keyframes”开头,后面紧接着是这个“动画的名称”加上一对花括号“{}”,括号中就是一些不同时间段样式规则。不同关键帧是通过from(相当于0%)、to(相当于100%)或百分比来表示(为了得到最佳的浏览器支持,建议使用百分比),如下定义一个简单的动画:

php 幼儿园源码,ubuntu怎么用nginx,到爬虫的功效,php数据库生成.php,seo56lzw

@keyframes myfirst /*定义动画名*/ { 0% {background:red; left:0px; top:0px;} /*定义起始帧样式,0%可以换成from*/ 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} /*定义结束帧样式,100%可以换成to*/ }

@keyframes定义好了,要使其能发挥效果,必须通过animation把它绑定到一个选择器,否则动画不会有任何效果。下面列出了animation的属性:

汽车门户小程序源码,ubuntu关闭鼠标唤醒,python爬虫项目书籍,备忘录源码php打包安装下载,seo rp值lzw

下面设置上述的所有属性

animation-name:myfirst; animation-duration:5s; animation-timing-function:linear; animation-delay:1s; animation-iteration-count:infinite; animation-direction:alternate; animation-play-state:running;

上述所有代码可以如下简写:

animation:myfirst 5s linear 2s infinite alternate; animation-play-state:running;

浏览器兼容性

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

Chrome 和 Safari 需要前缀 -webkit-。

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

下面给出上面介绍的关于keyframes和animation属性的完整代码示例:

animation演示p { width:100px; height:100px; background:red; position:relative; animation-name:myfirst; animation-duration:5s; animation-timing-function:linear; animation-delay:1s; animation-iteration-count:infinite; animation-direction:alternate; animation-play-state:running; /* Safari and Chrome: */ -webkit-animation-name:myfirst; -webkit-animation-duration:5s; -webkit-animation-timing-function:linear; -webkit-animation-delay:1s; -webkit-animation-iteration-count:infinite; -webkit-animation-direction:alternate; -webkit-animation-play-state:running; } @keyframes myfirst /*定义动画名*/ { 0% {background:red; left:0px; top:0px;} /*定义起始帧样式,0%相当于from*/ 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} /*定义结束帧样式,100%相当于to*/ } @-webkit-keyframes myfirst /* Safari and Chrome */ { 0% {background:red; left:0px; top:0px;} 25% {background:yellow; left:200px; top:0px;} 50% {background:blue; left:200px; top:200px;} 75% {background:green; left:0px; top:200px;} 100% {background:red; left:0px; top:0px;} }

该实例在 Internet Explorer 9 及更早 IE 版本是无效的。

上面代码演示了一个正方形沿着一个正方形轨迹运动,基数次按正方向运动,偶数次按反方向运动,运动过程中还带有颜色变化。具体效果,读者可以自行运行代码观察。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。