重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

CSS样式更改之如何实现过渡与动画

本篇内容介绍了“CSS样式更改之如何实现过渡与动画”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联公司长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为富源企业提供专业的网站设计、网站建设富源网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。

1.过渡
元素从一种样式逐渐改变为另一种的样式 。

div { transition: width 1s; -moz-transition: width 1s;  /* Firefox 4 */ -webkit-transition: width 1s;  /* Safari 和 Chrome */ -o-transition: width 1s;  /* Opera */ } transition-property:应用过渡的Css属性的名称 比如宽度width transition-duration:过渡效果花费的时间   比如1s transition-timing-function:渡效果的时间曲线 如下所示: linear 匀速 ease 先慢后快 ease-in 慢速开始 ease-out 慢速结束 ease-in-out 慢速开始和结束 cubic-bezier(n,n,n,n) 在cubic-bezie 函数中定义自己的值,可能的值是0至1之间的数值 transition-delay:过渡效果何时开始 如1s

2.动画 Animation
1).首先定义@keyframes 规则

@keyframes my { from {background: red;} to {background: yellow;} }  @-moz-keyframes my /* Firefox */ { from {background: red;} to {background: yellow;} }  @-webkit-keyframes my /* Safari 和 Chrome */ { from {background: red;} to {background: yellow;} }  @-o-keyframes my /* Opera */ { from {background: red;} to {background: yellow;} }

为了丰富元素的变化过程,你可以把from  to改为百分比的样子:

@keyframes my { 0%   {background: red;} 25%  {background: yellow;} 50%  {background: blue;} 100% {background: green;} }  @-moz-keyframes my /* Firefox */ { 0%   {background: red;} 25%  {background: yellow;} 50%  {background: blue;} 100% {background: green;} }  @-webkit-keyframes my /* Safari 和 Chrome */ { 0%   {background: red;} 25%  {background: yellow;} 50%  {background: blue;} 100% {background: green;} }  @-o-keyframes my /* Opera */ { 0%   {background: red;} 25%  {background: yellow;} 50%  {background: blue;} 100% {background: green;} }

定义好了,接下来我们就可以启动我们的动画了。

2).animation启动动画效果

div { animation-name: my; animation-duration: 5s; animation-timing-function: linear; animation-delay: 2s; animation-iteration-count: infinite; animation-direction: alternate; animation-play-state: running; /* Firefox: */ -moz-animation-name: my; -moz-animation-duration: 5s; -moz-animation-timing-function: linear; -moz-animation-delay: 2s; -moz-animation-iteration-count: infinite; -moz-animation-direction: alternate; -moz-animation-play-state: running; /* Safari 和 Chrome: */ -webkit-animation-name: my; -webkit-animation-duration: 5s; -webkit-animation-timing-function: linear; -webkit-animation-delay: 2s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-play-state: running; /* Opera: */ -o-animation-name: my; -o-animation-duration: 5s; -o-animation-timing-function: linear; -o-animation-delay: 2s; -o-animation-iteration-count: infinite; -o-animation-direction: alternate; -o-animation-play-state: running; }  animation-name                   选择器的 keyframes 的名称 animation-duration               动画所花费的时间 animation-timing-function        匀速播放动画 animation-delay           动画过多久开始 animation-iteration-count        播放动画次数 animation-direction       是否在下一周期逆向地播放 normal 正常播放  alternate 轮流反向播放 animation-play-state             暂停动画  paused 动画已暂停  running 动画正在播放 animation-fill-mode none         不填充 forwards     当动画完成后,保持最后一个属性值 backwards     在animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值 both        向前和向后填充模式都被应用。

“CSS样式更改之如何实现过渡与动画”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


文章题目:CSS样式更改之如何实现过渡与动画
分享路径:http://cqcxhl.com/article/jsospc.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP