日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
一個(gè)栗子上手CSS3動(dòng)畫(huà)

最近雜七雜八的事情很多,很多知識(shí)都沒(méi)來(lái)得及總結(jié),是時(shí)候總結(jié)總結(jié),開(kāi)啟新的篇章~

創(chuàng)新互聯(lián)是一家專業(yè)提供太和企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、做網(wǎng)站、H5網(wǎng)站設(shè)計(jì)、小程序制作等業(yè)務(wù)。10年已為太和眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

本篇文章不一一列舉CSS3動(dòng)畫(huà)的屬性,若需要了解API,可前往 MDN 。

在開(kāi)始栗子前,我們先補(bǔ)補(bǔ)基礎(chǔ)知識(shí)。

css3動(dòng)畫(huà)分類:

  • 補(bǔ)間動(dòng)畫(huà) – 具有連貫性的動(dòng)畫(huà)
  • 逐幀動(dòng)畫(huà) – 使用steps過(guò)渡方式實(shí)現(xiàn)跳躍

animation常用屬性及場(chǎng)景:

 
 
 
 
  1. animation: name duration timing-function delay iteration-count direction;

1. timing-function屬性:

  • ease 規(guī)定慢速開(kāi)始,然后變快,然后慢速結(jié)束的過(guò)渡效果。
  • ease-in 規(guī)定以慢速開(kāi)始的過(guò)渡效果。
  • ease-out 規(guī)定以慢速結(jié)束的過(guò)渡效果。
  • ease-in-out 規(guī)定以慢速開(kāi)始和結(jié)束的過(guò)渡效果。
  • linear 動(dòng)畫(huà)從頭到尾的速度是相同的。
  • cubic-bezier(n,n,n,n) 在cubic-bezier函數(shù)中自己的值,n取值為0~1
  • steps()

2. delay屬性:

用于將動(dòng)畫(huà)與其他動(dòng)畫(huà)的執(zhí)行時(shí)機(jī)錯(cuò)開(kāi),將動(dòng)畫(huà)落到不同的時(shí)間點(diǎn)。這個(gè)屬性很好用~

動(dòng)畫(huà)原則:

  1. 運(yùn)動(dòng)一般有個(gè)慣性,所以要先快后有一個(gè)慢一點(diǎn)的反彈。
  2. 背景若使用多個(gè)星星閃爍,錯(cuò)位閃爍

配合JS使用

 
 
 
 
  1. slide.addEventListener("webkitAnimationEnd", function() {
  2.    console.log('eeee') //動(dòng)畫(huà)結(jié)束再調(diào)用
  3. }); 

有些情況我們需要確保動(dòng)畫(huà)結(jié)束后再進(jìn)行另外一些交互,可使用該事件監(jiān)聽(tīng)。

實(shí)戰(zhàn)演習(xí):

假如我們需要實(shí)現(xiàn)一個(gè)這樣簡(jiǎn)單的動(dòng)畫(huà):

仔細(xì)觀察上面的動(dòng)畫(huà),我們發(fā)現(xiàn),它可以由以下3部分組成:

1. 入場(chǎng)動(dòng)畫(huà)——從右往左移動(dòng)

2. 左右循環(huán)移動(dòng)

3. 逐幀動(dòng)畫(huà)

實(shí)現(xiàn)方法:

使用3個(gè)dom元素,最外層dom實(shí)現(xiàn)入場(chǎng)動(dòng)畫(huà),第二層dom實(shí)現(xiàn)左右移動(dòng),第三層dom實(shí)現(xiàn)逐幀動(dòng)畫(huà)。

優(yōu)點(diǎn):調(diào)試方便,節(jié)省時(shí)間。

缺點(diǎn):dom多。

1. dom結(jié)構(gòu)

 
 
 
 
  1.     
  2.         
  •     
  •  

    2. 分析動(dòng)畫(huà)形成的時(shí)間軸:

    入場(chǎng)動(dòng)畫(huà)持續(xù)0.6s,只播放一次,左右移動(dòng)以及逐幀動(dòng)畫(huà)持續(xù)2s,循環(huán)播放,代碼如下:

     
     
     
     
    1. .anima_entrance {
    2.     animation: anima_entrance .6s ease-in-out both;
    3. }
    4.  
    5. .anima_move {
    6.     animation: anima_move 2s linear .6s infinite both;
    7. }
    8.  
    9. .anima_sprite {
    10.     animation: anima_sprite 2s step-end .6s infinite both;

    3. 使用steps()實(shí)現(xiàn)逐幀動(dòng)畫(huà):

    使用下面這張雪碧圖,通過(guò)改變background-position實(shí)現(xiàn)動(dòng)畫(huà)切換。

    蹬蹬蹬,效果如下面所示,是不是很失望

    原因:由于animation默認(rèn)以ease方式過(guò)渡,它會(huì)在每個(gè)關(guān)鍵幀之間插入補(bǔ)間動(dòng)畫(huà),所以動(dòng)畫(huà)效果是連貫性的。此時(shí)可以使用steps()取消補(bǔ)間動(dòng)畫(huà)。

    貼一個(gè)圖:

    steps(1,start): 動(dòng)畫(huà)一開(kāi)始就跳到 100% 直到這一幀(不是整個(gè)周期)結(jié)束 == step-start

    steps(1,end): 保持 0% 的樣式直到這一幀(不是整個(gè)周期)結(jié)束 == step-end

    接著,我們將timing-function改成 step-end,效果如下:

     
     
     
     
    1. animation: sprite 2s step-end .6s infinite both; 

    出現(xiàn)想要的效果了哈~不錯(cuò)。

    完整的css代碼如下:

     
     
     
     
    1.  .anima_entrance {
    2.     position: absolute;
    3.     z-index: 3;
    4.     top: 5.1rem;
    5.     left: 4.05rem;
    6.     width: 12.9rem;
    7.     height: 19.1rem;
    8.     -webkit-animation: anima_entrance .6s ease-in-out both;
    9.     animation: anima_entrance .6s ease-in-out both;
    10. }
    11.  
    12. .anima_move {
    13.     width: 218px;
    14.     height: 382px;
    15.     position: absolute;
    16.     z-index: 1;
    17.     top: 0;
    18.     left: 42px;
    19.     -webkit-animation: anima_move 2s linear .6s infinite both;
    20.     animation: anima_move 2s linear .6s infinite both;
    21. }
    22.  
    23. .anima_sprite {
    24.     width: 218px;
    25.     height: 382px;
    26.     background: url(demo.png) no-repeat 0 0;
    27.     background-size: 25.8rem 19.1rem;
    28.     -webkit-animation: anima_sprite 2s step-end .6s infinite both;
    29.     animation: anima_sprite 2s step-end .6s infinite both;
    30. }
    31.  
    32. @keyframes anima_entrance {
    33.     0% {
    34.         -webkit-transform: translate3d(18.75rem, 0, 0);
    35.         transform: translate3d(18.75rem, 0, 0);
    36.     }
    37.     100% {
    38.         -webkit-transform: translate3d(0, 0, 0);
    39.         transform: translate3d(0, 0, 0);
    40.     }
    41. }
    42.  
    43. @keyframes anima_move {
    44.     0%, 16%, 42%, 74%, 100% {
    45.         -webkit-transform: translate3d(0, 0, 0);
    46.         transform: translate3d(0, 0, 0);
    47.     }
    48.     29% {
    49.         -webkit-transform: translate3d(-1rem, 0, 0);
    50.         transform: translate3d(-1rem, 0, 0);
    51.     }
    52.     87% {
    53.         -webkit-transform: translate3d(1rem, 0, 0);
    54.         transform: translate3d(1rem, 0, 0);
    55.     }
    56. }
    57.  
    58. @keyframes anima_sprite {
    59.     0%, 16%, 42%, 58%, 74%, 100% {
    60.         background-position: -12.9rem 0;
    61.     }
    62.     8%, 50%, 66% {
    63.         background-position: 0 0;
    64.     }

    名稱欄目:一個(gè)栗子上手CSS3動(dòng)畫(huà)
    標(biāo)題路徑:http://m.5511xx.com/article/dpgpdih.html