CSS3中Animation动画属性用法详解
建站知识 2021-07-03 08:15www.168986.cn长沙网站建设
要使用animation动画,先要熟悉一下keyframes,Keyframes的语法规则:命名是由”开头,后面紧接着是这个“动画的名称”加上一对花括号“{}”,括号中就是一些不间段样式规则。不同关键帧是通过from(相当于0%)、to(相当于100%)或百分比来表示(为了得到最佳的浏览器支持,建议使用百分比),如下定义一个简单的动画
CSS Code复制内容到剪贴板
- @keyframes myfirst /定义动画名/
- {
- 0% {background:red; left:0px; :0px;} /定义起始帧样式,0%可以换成from/
- 25% {background:yellow; left:200px; :0px;}
- 50% {background:blue; left:200px; :200px;}
- 75% {background:green; left:0px; :200px;}
- 100% {background:red; left:0px; :0px;} /定义结束帧样式,100%可以换成to/
- }
@keyframes定义好了,要使其能发挥效果,必须通过animation把它绑定到一个选择器,否则动画不会有任何效果。狼蚁网站SEO优化列出了animation的属性
狼蚁网站SEO优化设置上述的所有属性
CSS Code复制内容到剪贴板
- animation-name:myfirst;
- animation-duration:5s;
- animation-timing-function:linear;
- animation-delay:1s;
- animation-iteration-count:infinite;
- animation-direction:alternate;
- animation-play-state:running;
上述所有代码可以如下简写
CSS Code复制内容到剪贴板
- animation:myfirst 5s linear 2s infinite alternate;
- animation-play-state:running;
浏览器兼容性
Inter Explorer 10、Firefox 以及 Opera 支持 @keyframes 规则和 animation 属性。
Chrome 和 Safari 需要前缀 -webkit-。
注意Inter Explorer 9,以及更早的版本,不支持 @keyframe 规则或 animation 属性。
狼蚁网站SEO优化给出上面介绍的关于keyframes和animation属性的完整代码示例
XML/HTML Code复制内容到剪贴板
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>animation演示</title>
- <style>
- div
- {
- 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; :0px;} /定义起始帧样式,0%相当于from/
- 25% {background:yellow; left:200px; :0px;}
- 50% {background:blue; left:200px; :200px;}
- 75% {background:green; left:0px; :200px;}
- 100% {background:red; left:0px; :0px;} /定义结束帧样式,100%相当于to/
- }
- @-webkit-keyframes myfirst / Safari and Chrome /
- {
- 0% {background:red; left:0px; :0px;}
- 25% {background:yellow; left:200px; :0px;}
- 50% {background:blue; left:200px; :200px;}
- 75% {background:green; left:0px; :200px;}
- 100% {background:red; left:0px; :0px;}
- }
- </style>
- </head>
- <body>
- <p>该实例在 Inter Explorer 9 及更早 IE 版本是无效的。</p>
- <div></div>
- </body>
- </html>
上面代码演示了一个正方形沿着一个正方形轨迹运动,基数次按正方向运动,偶数次按反方向运动,运动过程中还带有颜色变化。具体效果,读者可以自行运行代码观察。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
长沙网站设计
- 中小企业SEO优化的技巧(从研究到外链建设,这
- 建站申请书 建站申请书范文
- 影响seo排名的因素有哪些(影响网站速度的因素
- SEO技巧url静态化是什么意思(附动态页面静态化
- 如何提升网站的百度快速收录排名(提升百度S
- 付费社群app 付费社群软件有哪些
- 常州网站开发公司推荐
- seo实战指导 pdf
- 如何快速恢复被降权的网站排名(排除5个影响因
- 新网站如何快速提高搜索引擎排名权重?新站S
- 广告云建站 广告资源发布平台
- 汕头建站前端模板
- 如何进行百度SEO分析?(提升百度排名的关键技
- 提高网站排名SEO的10个窍门(让您的网站在搜索引
- 如何优化网站排名关键词(提高网站排名的8种方
- 迁西个人网页设计制作软件