CSS樣式更改之如何實(shí)現(xiàn)過渡與動(dòng)畫

本篇內(nèi)容介紹了“CSS樣式更改之如何實(shí)現(xiàn)過渡與動(dòng)畫”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

成都創(chuàng)新互聯(lián)公司長(zhǎng)期為成百上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為富源企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)富源網(wǎng)站改版等技術(shù)服務(wù)。擁有10多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

1.過渡
元素從一種樣式逐漸改變?yōu)榱硪环N的樣式 。

div { transition: width 1s; -moz-transition: width 1s;  /* Firefox 4 */ -webkit-transition: width 1s;  /* Safari 和 Chrome */ -o-transition: width 1s;  /* Opera */ } transition-property:應(yīng)用過渡的Css屬性的名稱 比如寬度width transition-duration:過渡效果花費(fèi)的時(shí)間   比如1s transition-timing-function:渡效果的時(shí)間曲線 如下所示: linear 勻速 ease 先慢后快 ease-in 慢速開始 ease-out 慢速結(jié)束 ease-in-out 慢速開始和結(jié)束 cubic-bezier(n,n,n,n) 在cubic-bezie 函數(shù)中定義自己的值,可能的值是0至1之間的數(shù)值 transition-delay:過渡效果何時(shí)開始 如1s

2.動(dòng)畫 Animation
1).首先定義@keyframes 規(guī)則

@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;} }

定義好了,接下來我們就可以啟動(dòng)我們的動(dòng)畫了。

2).animation啟動(dòng)動(dòng)畫效果

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               動(dòng)畫所花費(fèi)的時(shí)間 animation-timing-function        勻速播放動(dòng)畫 animation-delay           動(dòng)畫過多久開始 animation-iteration-count        播放動(dòng)畫次數(shù) animation-direction       是否在下一周期逆向地播放 normal 正常播放  alternate 輪流反向播放 animation-play-state             暫停動(dòng)畫  paused 動(dòng)畫已暫停  running 動(dòng)畫正在播放 animation-fill-mode none         不填充 forwards     當(dāng)動(dòng)畫完成后,保持最后一個(gè)屬性值 backwards     在animation-delay 所指定的一段時(shí)間內(nèi),在動(dòng)畫顯示之前,應(yīng)用開始屬性值 both        向前和向后填充模式都被應(yīng)用。

“CSS樣式更改之如何實(shí)現(xiàn)過渡與動(dòng)畫”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文名稱:CSS樣式更改之如何實(shí)現(xiàn)過渡與動(dòng)畫
當(dāng)前URL:http://www.muchs.cn/article32/jsospc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站改版、品牌網(wǎng)站設(shè)計(jì)定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)