這篇文章主要介紹“CSS3怎么實(shí)現(xiàn)動(dòng)畫按鈕效果”,在日常操作中,相信很多人在CSS3怎么實(shí)現(xiàn)動(dòng)畫按鈕效果問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”CSS3怎么實(shí)現(xiàn)動(dòng)畫按鈕效果”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
作為一家“創(chuàng)意+整合+營銷”的成都網(wǎng)站建設(shè)機(jī)構(gòu),我們?cè)跇I(yè)內(nèi)良好的客戶口碑。創(chuàng)新互聯(lián)公司提供從前期的網(wǎng)站品牌分析策劃、網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、做網(wǎng)站、創(chuàng)意表現(xiàn)、網(wǎng)頁制作、系統(tǒng)開發(fā)以及后續(xù)網(wǎng)站營銷運(yùn)營等一系列服務(wù),幫助企業(yè)打造創(chuàng)新的互聯(lián)網(wǎng)品牌經(jīng)營模式與有效的網(wǎng)絡(luò)營銷方法,創(chuàng)造更大的價(jià)值。
在線演示地址:http://jsfiddle.net/lhb25/9EcuV/8/embedded/result/
HTML 部分非常簡單,五種效果對(duì)應(yīng)的class為:praticle、cells、jelly、blobbs、chase,代碼如下:
<section> <div class="particle"></div> <div class="cells"></div> <div class="jelly"></div> <div class="blobbs"></div> <div class="chase"></div> </section>
這些精美的效果用到了 CSS3 border-radius(圓角)、box-shadow(陰影)、transition(變形)、transform(轉(zhuǎn)換)和 animation(動(dòng)畫)等特性,公共部分的完整代碼如下:
section > div { display: inline-block; position: relative; width: 200px; height: 200px; margin: 0px auto; border-radius: 50%; border: 10px solid hsla(0,0%,0%,.7); box-shadow: inset 0 15px 15px -5px hsla(0,0%,100%,.7), inset 0 -5px 10px 3px hsla(0,0%,0%,.6), 0 8px 10px 2px hsla(0,0%,0%,.3); background-position: center; -webkit-transform: scale3d(.66,.66,1); -moz-transform: scale(.66); -ms-transform: scale(.66); -o-transform: scale(.66); transform: scale(.66); -webkit-transition: -webkit-transform .5s cubic-bezier(.32,0,.15,1); -moz-transition: -moz-transform .5s cubic-bezier(.32,0,.15,1); -ms-transition: -ms-transform .5s cubic-bezier(.32,0,.15,1); -o-transition: -o-transform .5s cubic-bezier(.32,0,.15,1); transition: transform .5s cubic-bezier(.32,0,.15,1); } section > div:hover { cursor: none; -webkit-transform: scale3d(1,1,1); -moz-transform: scale(1); -ms-transform: scale(1); -o-transform: scale(1); transform: scale(1); -webkit-transition: -webkit-transform .2s cubic-bezier(.32,0,.15,1); -moz-transition: -moz-transform .2s cubic-bezier(.32,0,.15,1); -ms-transition: -ms-transform .2s cubic-bezier(.32,0,.15,1); -o-transition: -o-transform .2s cubic-bezier(.32,0,.15,1); transition: transform .2s cubic-bezier(.32,0,.15,1); }
這段代碼看起來很長很復(fù)雜,其實(shí)大部分是兼容性代碼,精簡以后的代碼如下:
section > div { display: inline-block; position: relative; width: 200px; height: 200px; margin: 0px auto; /*對(duì)于正方形元素border-radius設(shè)置為50%剛好變成圓形*/ border-radius: 50%; /*寬度為10px的、不透明度為0.7的黑色邊框效果*/ border: 10px solid hsla(0,0%,0%,.7); /*通過邊框陰影實(shí)現(xiàn)立體按鈕效果,inset是內(nèi)陰影效果*/ box-shadow: inset 0 15px 15px -5px hsla(0,0%,100%,.7), inset 0 -5px 10px 3px hsla(0,0%,0%,.6), 0 8px 10px 2px hsla(0,0%,0%,.3); background-position: center; /*初始縮放0.66倍*/ transform: scale(.66); /*在失去焦點(diǎn)時(shí)根據(jù)自定義的貝塞爾時(shí)間曲線做動(dòng)畫變換效果*/ transition: transform .5s cubic-bezier(.32,0,.15,1); } section > div:hover { cursor: none; /*懸停時(shí)恢復(fù)原始大小*/ transform: scale(1); /*鼠標(biāo)懸停時(shí)根據(jù)自定義的貝塞爾時(shí)間曲線做動(dòng)畫變換效果*/ transition: transform .2s cubic-bezier(.32,0,.15,1); }
上面的代碼中用到了貝塞爾曲線,在數(shù)學(xué)的數(shù)值分析領(lǐng)域中,貝塞爾曲線又稱貝賽爾曲線(Bézier曲線)是電腦圖形學(xué)中相當(dāng)重要的參數(shù)曲線。更高維度的廣泛化貝塞爾曲線就稱作貝塞爾曲面,其中貝塞爾三角是一種特殊的實(shí)例。
貝塞爾曲線于1962年,由法國工程師皮埃爾·貝塞爾(Pierre Bézier)所廣泛發(fā)表,他運(yùn)用貝塞爾曲線來為汽車的主體進(jìn)行設(shè)計(jì)。貝塞爾曲線最初由Paul de Casteljau于1959年運(yùn)用de Casteljau算法開發(fā),以穩(wěn)定數(shù)值的方法求出貝塞爾曲線。
想更加深入的了解貝塞爾曲線可以到維基百科了解:貝塞爾曲線。下面是五種效果的完整代碼:
效果一(Praticle)的完整代碼:
.particle { background-size: 12px 12px; background-color: #000; /* the default highlight was too strong */ box-shadow: inset 0 15px 15px -5px hsla(0,0%,100%,.25), inset 0 -5px 10px 3px hsla(0,0%,0%,.6), 0 8px 10px 2px hsla(0,0%,0%,.3); background-image: -webkit-radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), -webkit-repeating-radial-gradient( white 0px, black 2px, black 48px); background-image: -moz-radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), -moz-repeating-radial-gradient( white 0px, black 2px, black 48px); background-image: -ms-radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), -ms-repeating-radial-gradient( white 0px, black 2px, black 48px); background-image: -o-radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), -o-repeating-radial-gradient( white 0px, black 2px, black 48px); background-image: radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), repeating-radial-gradient( white 0px, black 2px, black 48px); } .particle:hover { -webkit-animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; -moz-animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; -ms-animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; -o-animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; } @-webkit-keyframes particle-size { from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @-moz-keyframes particle-size { from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @-ms-keyframes particle-size { from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @-o-keyframes particle-size { from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @keyframes particle-size { from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @-webkit-keyframes particle-positon { from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } } @-moz-keyframes particle-positon { from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } } @-ms-keyframes particle-positon { from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } } @-o-keyframes particle-positon { from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } } @keyframes particle-positon { from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } }
這個(gè)效果使用了 CSS3 radial-gradient(徑向漸變或者放射性漸變,另外一種是線性漸變)、repeating-radial-gradient(重復(fù)漸變)以及 CSS3 Animation(動(dòng)畫),關(guān)于 CSS3 漸變的詳細(xì)使用方法可以參考這篇文章:CSS3 Gradient,CSS3 動(dòng)畫可以參考這篇文章:CSS3 Animation。
為了便于閱讀和學(xué)習(xí),效果一的代碼精簡后如下:
.particle { background-size: 12px 12px; background-color: #000; /*前面公共樣式部分box-shadow產(chǎn)生的高亮效果太強(qiáng),這里重新配置*/ box-shadow: inset 0 15px 15px -5px hsla(0,0%,100%,.25), inset 0 -5px 10px 3px hsla(0,0%,0%,.6), 0 8px 10px 2px hsla(0,0%,0%,.3); /*使用徑向漸變和重復(fù)漸變來實(shí)現(xiàn)背景圖片效果*/ background-image: radial-gradient( #555 0px, hsla(0,0%,0%,0) 2px, hsla(0,0%,0%,0) 24px), repeating-radial-gradient( white 0px, black 2px, black 48px); } .particle:hover { /*鼠標(biāo)懸停的時(shí)候執(zhí)行particle-size和particle-positon兩個(gè)動(dòng)畫效果*/ animation: particle-size .24s linear infinite, particle-positon .48s linear infinite alternate; } @keyframes particle-size { /*這個(gè)名為particle-size的關(guān)鍵幀用來產(chǎn)生背景尺寸變化動(dòng)畫效果*/ from { background-size: 6px 6px, 12px 12px; } to { background-size: 12px 12px, 24px 24px; } } @keyframes particle-positon { /*這個(gè)名為particle-positon的關(guān)鍵幀用來產(chǎn)生背景位置變化動(dòng)畫效果*/ from { background-position: 60px, 60px; } to { background-position: 140px, 140px; } }
效果二(Cells)的完整代碼:
.cells { background-size: 24px 24px; background-color: #fff; background-image: -webkit-repeating-radial-gradient( black 8px, white 12px); background-image: -moz-repeating-radial-gradient( black 8px, white 12px); background-image: -ms-repeating-radial-gradient( black 8px, white 12px); background-image: -o-repeating-radial-gradient( black 8px, white 12px); background-image: repeating-radial-gradient( black 8px, white 12px); } .cells:hover { -webkit-animation: cells 0.4s linear infinite; -moz-animation: cells 0.4s linear infinite; -ms-animation: cells 0.4s linear infinite; -o-animation: cells 0.4s linear infinite; animation: cells 0.4s linear infinite; } @-webkit-keyframes cells { from { background-size: 12px 12px; } to { background-size: 24px 24px; } } @-moz-keyframes cells { from { background-size: 12px 12px; } to { background-size: 24px 24px; } } @-ms-keyframes cells { from { background-size: 12px 12px; } to { background-size: 24px 24px; } } @-o-keyframes cells { from { background-size: 12px 12px; } to { background-size: 24px 24px; } } @keyframes cells { from { background-size: 12px 12px; } to { background-size: 24px 24px; } }
效果二代碼和效果一代碼類似,差別是效果二的背景是只用了重復(fù)漸變(repeating-radial-gradient),動(dòng)畫效果只是背景尺寸(background-size)的變化,精簡后的代碼如下:
.cells { background-size: 24px 24px; background-color: #fff; /*使用重復(fù)徑向漸變特性來實(shí)現(xiàn)背景圖片效果*/ background-image: repeating-radial-gradient( black 8px, white 12px); } .cells:hover { /*鼠標(biāo)懸停的時(shí)候執(zhí)行cells動(dòng)畫效果*/ animation: cells 0.4s linear infinite; } @keyframes cells { /*定義一個(gè)名為cells的關(guān)鍵幀用來產(chǎn)生背景尺寸變化動(dòng)畫效果*/ from { background-size: 12px 12px; } to { background-size: 24px 24px; } }
效果三(Jelly)的完整代碼:
.jelly { background-size: 60px 60px; background-color: hsla(320,80%,60%,1); background-image: -webkit-repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), -webkit-repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); background-image: -moz-repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), -moz-repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); background-image: -ms-repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), -ms-repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); background-image: -o-repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), -o-repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); background-image: repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); } .jelly:hover { -webkit-animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; -moz-animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; -ms-animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; -o-animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; } @-webkit-keyframes jelly { from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } } @-moz-keyframes jelly { from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } } @-ms-keyframes jelly { from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } } @-o-keyframes jelly { from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } } @keyframes jelly { from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } }
效果三和效果一的代碼類似,不同的地方是動(dòng)畫多了個(gè) 50% 關(guān)鍵幀,精簡后的代碼如下:
.jelly { background-size: 60px 60px; background-color: hsla(320,80%,60%,1); /*使用徑向漸變和重復(fù)漸變來實(shí)現(xiàn)背景圖片效果*/ background-image: repeating-radial-gradient( hsla(320,100%,60%,.6) 0px, hsla(220,100%,60%,0) 60%), repeating-radial-gradient( hsla(330,100%,40%,1) 12%, hsla(320,80%,60%,1) 24px); } .jelly:hover { /*鼠標(biāo)懸停的時(shí)候執(zhí)行jelly動(dòng)畫效果*/ animation: jelly 1.4s cubic-bezier(.1,.4,.9,.6) infinite; } @keyframes jelly { /*定義一個(gè)名為jelly的關(guān)鍵幀用來產(chǎn)生背景尺寸變化動(dòng)畫效果*/ from { background-size: 60px 60px, 24px 24px; } 50% { background-size: 120px 120px, 100px 100px; } to { background-size: 24px 24px, 140px 140px; } }
效果四(Blobbs)的完整代碼:
.blobbs { background-size: 66px 66px; background-color: hsl(200,100%,50%); background-image: -webkit-repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), -webkit-repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); background-image: -moz-repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), -moz-repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); background-image: -ms-repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), -ms-repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); background-image: -o-repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), -o-repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); background-image: repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); } .blobbs:hover { -webkit-animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; -moz-animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; -ms-animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; -o-animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; } @-webkit-keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-moz-keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-ms-keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-o-keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-webkit-keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } } @-moz-keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } } @-ms-keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } } @-o-keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } } @keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } }
效果四的背景位置變化動(dòng)畫有0%,25%,50%,75%和100%五個(gè)關(guān)鍵幀,動(dòng)畫效果更豐富,精簡后的代碼如下:
.blobbs { background-size: 66px 66px; background-color: hsl(200,100%,50%); background-image: repeating-radial-gradient( hsla(200,100%,80%,.8) 0px, hsla(200,100%,80%,.5) 4px, hsla(200,100%,80%,0) 50px), repeating-radial-gradient( hsla(260,100%, 0%, 0) 0px, hsla(260,100%,50%,.1) 2px, hsla(260,100%, 0%,0) 10px); } .blobbs:hover { animation: blobbs-position 6s cubic-bezier(.4,0,.2,1) infinite, blobbs-size .75s cubic-bezier(.4,0,.2,1) infinite alternate; } @keyframes blobbs-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @keyframes blobbs-size { from { background-size: 200px 200px, 200px 200px; } to { background-size: 66px 66px, 66px 66px; } }
效果五(Chase)的完整代碼:
.chase { background-repeat: no-repeat, repeat; background-size: 180px 180px; background-color: hsl(50,100%,70%); background-image: -webkit-repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), -webkit-repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); background-image: -moz-repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), -moz-repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); background-image: -ms-repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), -ms-repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); background-image: -o-repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), -o-repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); background-image: repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); } .chase:hover { -webkit-animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; -moz-animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; -ms-animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; -o-animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; } @-webkit-keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-moz-keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-ms-keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-o-keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @-webkit-keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } } @-moz-keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } } @-ms-keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } } @-o-keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } } @keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } }
最后這個(gè)效果比前面四個(gè)效果都更復(fù)雜,背景位置變化動(dòng)畫有0%,25%,50%,75%和100%五個(gè)關(guān)鍵幀,背景尺寸的變化動(dòng)畫有0%(from),50%,100%(to)三個(gè)關(guān)鍵幀,精簡后的代碼如下:
.chase { background-repeat: no-repeat, repeat; background-size: 180px 180px; background-color: hsl(50,100%,70%); background-image: repeating-radial-gradient( hsla(50,100%,100%,1) 0px, hsla(50,100%,90%, 1) 10px, hsla(50,100%,70%,.2) 12px, hsla(50,100%,70%,0) 130px), repeating-radial-gradient( hsla(20,100%, 50%,0) 20%, hsla(20,100%,50%,.4) 80%, hsla(50,100%,70%, 1) 120px); } .chase:hover { animation: chase-position 1.2s infinite, chase-size .4s infinite alternate; } @keyframes chase-position { 0% { background-position: left top, left top; } 25% { background-position: right top, left bottom; } 50% { background-position: right bottom, right bottom; } 75% { background-position: left bottom, right top; } 100% { background-position: left top, left top; } } @keyframes chase-size { from { background-size: 120px 120px, 300px 300px; } 50% { background-size: 160px 160px, 150px 150px; } to { background-size: 180px 180px, 100px 100px; } }
到此,關(guān)于“CSS3怎么實(shí)現(xiàn)動(dòng)畫按鈕效果”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
本文名稱:CSS3怎么實(shí)現(xiàn)動(dòng)畫按鈕效果
網(wǎng)頁URL:http://chinadenli.net/article38/gphhsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、企業(yè)網(wǎng)站制作、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)