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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
純CSS3畫出小黃人并實現(xiàn)動畫效果

前言

前兩天我剛發(fā)布了一篇CSS3實現(xiàn)小黃人動畫的博客,但是實現(xiàn)的CSS3動畫是基于我在站酷網(wǎng)找到的一張小黃人的jpg格式圖片,并自己用PS摳出需要實現(xiàn)動畫的部分,***才完成的動畫效果。但是,其實我的初衷是想體驗一下用圖片做動畫的趕腳,但是找不到素材,才無奈用了最笨的方法來滿足自己的需求,本想勉強能看就行了??墒悄?,還是抵不住自己內(nèi)心的***,于是乎,用了一個晚上用CSS3畫出了小黃人再實現(xiàn)類似的動畫效果。

正題

OK,大家看一下下面兩張圖有什么不同:

當(dāng)然,很多人會說,明顯大小不同,嘴巴,頭發(fā)也是不一樣的。但是其實***的不同是,用一個形象一點的例子就是:這是兩個孩子,***個是從超市貨架上拿的,另外一個是我自己生的。怎么生呢?——用CSS3!

那么生下來得會動啊,不然就夭折了,所以,我就多拍了幾個,就變成這樣子了:

怎么樣?雖然手腳動畫還是不怎么神似,但人類聰明地大腦還是能看得出啥意思的吧!今天就讓我們一起學(xué)習(xí)如何生出一個小黃人來。

首先,還是直接把HTML結(jié)構(gòu)放出來給大家打量打量:

 
 
 
 
  1.         
  2.             
  3.                 
  4.                     
  5.                         
  •                         
  •                     
  •                     
  •                     
  •                     
  •                     
  •                     
  •                     
  •                 
  •             
  •             
  •                 
  •                 
  •             
  •             
  •                 
  •                     
  •                         
  •                     
  •                 
  •                 
  •                     
  •                         
  •                     
  •                 
  •             
  •             
  •                 
  •             
  •             
  •                 
  •                 
  •             
  •             
  •                 
  •                 
  •             
  •             
  •         
  •      
  • 好的,每一處我都標(biāo)明了它的用途,大家可以稍微理解一下,在頭腦里有一個大概的模型或者層次結(jié)構(gòu)。

    接下來就是猛料了。。。我將分步講解,一步一步實現(xiàn):

    首先對容器和整體做一些簡單的樣式設(shè)置:

     
     
     
     
    1. body{
    2.     margin: 0;
    3.     padding:0;
    4. }
    5. .wrapper{
    6.     width: 300px;
    7.     margin:100px auto;
    8. }
    9. .litteH{
    10.     position: relative;
    11. }
    12. .bodyH{
    13.     position: absolute;
    14.     width: 240px;
    15.     height: 400px;
    16.     border:5px solid #000;
    17.     border-radius: 115px;
    18.     background: rgb(249,217,70);
    19.     overflow: hidden;
    20.     z-index: 2;

    其中.bodyH主要就是繪制小黃人的身體,身體的比例很重要,現(xiàn)在運行看一下效果:

    OK,身體已經(jīng)有了,現(xiàn)在趕緊給它穿個褲子吧!

     
     
     
     
    1. .bodyH .condoleBelt{
    2.     position: absolute;
    3. }
    4. .bodyH .trousers{
    5.     position: absolute;
    6.     bottom: 0;
    7.     width: 100%;
    8.     height: 100px;
    9.     border-top: 6px solid #000;
    10.     background: rgb(32,116,160);
    11. }
    12. .trousers_top{
    13.     width: 160px;
    14.     height: 60px;
    15.     border:6px solid #000;
    16.     border-bottom: none;
    17.     border-radius: 0 0 5px 5px;
    18.     background: rgb(32,116,160);
    19.     position: absolute;
    20.     bottom: 100px;
    21.     left:34px;

    其中.trousers_top就是矩形部分,那么穿完褲子是什么樣子的呢?

    現(xiàn)在怎么看都像一顆膠囊,不行,趕緊修飾修飾,給它一個吊帶,不然褲子會掉呢:

     
     
     
     
    1. .bodyH .condoleBelt .left,
    2. .bodyH .condoleBelt .right{
    3.     width: 100px;
    4.     height: 16px;
    5.     border:5px solid #000;
    6.     background: rgb(32,116,160);
    7.     position: absolute;
    8.     top:-90px;
    9.     left:-35px;
    10.     z-index: 2;
    11.     -webkit-transform:rotate(45deg);
    12. }
    13. .bodyH .condoleBelt .left{
    14.     top:-88px;
    15.     left:165px;
    16.     -webkit-transform:rotate(-45deg);
    17. }
    18. .bodyH .condoleBelt .left:after,
    19. .bodyH .condoleBelt .right:after{
    20.     content: '';
    21.     width: 8px;
    22.     height: 8px;
    23.     border-radius: 50%;
    24.     background: #000;
    25.     position: absolute;
    26.     top:4px;
    27.     left:88px;
    28. }
    29.  
    30. .bodyH .condoleBelt .left:after{
    31.     left:5px;

    這一塊主要就是實現(xiàn)兩個吊帶,左右各一條,然后我使用:after偽元素來實現(xiàn)吊帶上的小黑點:

    咦,開始有模有樣了,接下來我們一鼓作氣把褲袋和一下修飾的邊邊給實現(xiàn)了:

     
     
     
     
    1. .pocket{
    2.     width: 60px;
    3.     height: 45px;
    4.     border:6px solid #000;
    5.     border-radius: 0px 0px 25px 25px;
    6.     position: absolute;
    7.     bottom:65px;
    8.     left:84px;
    9. }
    10. .line_right{
    11.     width: 30px;
    12.     height: 30px;
    13.     border-bottom-left-radius: 100px;
    14.     border-bottom:6px solid #000;
    15.     border-left:6px solid #000;
    16.     position: absolute;
    17.     left: 0;
    18.     bottom:60px;
    19.     -webkit-transform:rotate(-75deg);
    20. }
    21. .line_left{
    22.     width: 30px;
    23.     height: 30px;
    24.     border-bottom-right-radius: 100px;
    25.     border-bottom:6px solid #000;
    26.     border-right:6px solid #000;
    27.     position: absolute;
    28.     right: 0;
    29.     bottom:63px;
    30.     -webkit-transform:rotate(75deg);
    31. }
    32. .line_bottom{
    33.     height: 40px;
    34.     border:3px solid #000;
    35.     border-radius: 3px;
    36.     position: absolute;
    37.     left:118px;
    38.     bottom: 0px;

    先看效果圖:

    OK,兩個注意點說一下:

    1.我把褲子放在身體里面,然后給.bodyH添加overflow:hidden,這樣我們就不用去多慮溢出怎么辦,而且很輕松就能實現(xiàn)褲子的效果;

    2.可以看到褲子兩邊有兩條有弧度的曲線段,我是通過給矩形某一個角實現(xiàn)圓角效果,然后只設(shè)置與這個角相鄰的兩條邊的邊框樣式,然后旋轉(zhuǎn)一下角度就實現(xiàn)這個效果了,當(dāng)然只能實現(xiàn)簡單一點的效果。

    好的,我們繼續(xù),接下來先實現(xiàn)以下眼睛部分吧:

     
     
     
     
    1. .eyes{
    2.     position: relative;
    3.     z-index: 3;
    4. }
    5. .eyes .leftEye,.eyes .rightEye{
    6.     width: 85px;
    7.     height: 85px;
    8.     border-radius: 50%;
    9.     border:6px solid #000;
    10.     background: #fff;
    11.     position: absolute;
    12.     top:60px;
    13.     left: 27px;
    14. }
    15. .eyes .leftEye{
    16.     left: 124px;
    17. }
    18. .eyes .leftEye .left_blackEye,
    19. .eyes .rightEye .right_blackEye{
    20.     width: 40px;
    21.     height: 40px;
    22.     border-radius: 50%;
    23.     background: #000;
    24.     position: absolute;
    25.     top:24px;
    26.     left:22px;
    27. }
    28. .eyes .leftEye .left_blackEye .left_white,
    29. .eyes .rightEye .right_blackEye .right_white{
    30.     width: 20px;
    31.     height: 20px;
    32.     border-radius: 50%;
    33.     background: #fff;
    34.     position: absolute;
    35.     top:7px;
    36.     left:17px;
    37. }
    38. .eyes .leftEye .left_blackEye .left_white{
    39.     top:4px;
    40.     left:17px;
    41. }
    42. .eyes .leftEye:after,
    43. .eyes .rightEye:after{
    44.     content: '';
    45.     width: 28px;
    46.     height: 18px;
    47.     background: #000;
    48.     position: absolute;
    49.     left:-30px;
    50.     top:37px;
    51.     -webkit-transform:skewX(20deg) rotate(7deg);
    52. }
    53. .eyes .leftEye:after{
    54.     left:89px;
    55.     top:37px;
    56.     -webkit-transform:skewX(-20deg) rotate(-7deg);

    眼睛部分還是挺好實現(xiàn)的,先畫眼鏡,然后黑眼珠,再畫白點,***我才畫的眼鏡框,眼睛框我是用:after偽元素實現(xiàn)的。效果圖如下:

    嘴巴是最困惑我的,但還是***還是能實現(xiàn):

     
     
     
     
    1. .mouse{
    2.     position: relative;
    3. }
    4. .mouse .mouse_shape{
    5.     width: 55px;
    6.     height: 35px;
    7.     border:5px solid #000;
    8.     border-bottom-left-radius: 30px;
    9.     background: #fff;
    10.     position: absolute;
    11.     top:175px;
    12.     left:98px;
    13.     z-index: 3;
    14.     -webkit-transform:rotate(-35deg);

    首先也是通過矩形其中一個角實現(xiàn)圓角來模擬嘴巴形狀,再加以旋轉(zhuǎn):

    結(jié)果是這樣的,那么想要達(dá)到我們預(yù)期的效果,就需要把上半部分給遮掉,所以我用:after偽元素來實現(xiàn)遮罩效果:

     
     
     
     
    1. .mouse .mouse_shape:after{
    2.     content: '';
    3.     width: 70px;
    4.     height: 32px;
    5.     border-bottom:5px solid #000;
    6.     border-radius:35px 26px 5px 5px;
    7.     background: red;
    8.     position: absolute;
    9.     top:-16px;
    10.     left:3px;
    11.     -webkit-transform:rotate(34deg);} 

    這個地方就需要慢慢調(diào)到合適的位置,模擬圖如下:

    紅色部分就是遮罩了,也是一個矩形,設(shè)置了底邊框,實現(xiàn)和嘴巴下半部分形成閉合效果,現(xiàn)在我們就可以把顏色改成膚色就行了:

     
     
     
     
    1. .mouse .mouse_shape:after{
    2.     content: '';
    3.     width: 70px;
    4.     height: 32px;
    5.     border-bottom:5px solid #000;
    6.     border-radius:35px 26px 5px 5px;
    7.     background: rgb(249,217,70);
    8.     position: absolute;
    9.     top:-16px;
    10.     left:3px;
    11.     -webkit-transform:rotate(34deg);
    12.     -webkit-animation: mouse_mask 5s ease-in-out infinite;

    效果圖如下:

    接下來實現(xiàn)雙手部分,這一部分不難,就是兩個圓角矩形,旋轉(zhuǎn)了角度,然后層級低于身體的層級就行,然后再通過:after偽元素實現(xiàn)胳膊關(guān)節(jié)處就搞定了。

     
     
     
     
    1. .hands{
    2.     position: relative;
    3. }
    4. .hands .leftHand,
    5. .hands .rightHand{
    6.     width: 80px;
    7.     height: 80px;
    8.     border:6px solid #000;
    9.     border-radius: 25px;
    10.     background: rgb(249,217,70);
    11.     position: absolute;
    12.     top:220px;
    13.     left:-23px;
    14.     -webkit-transform:rotate(40deg);
    15. }
    16. .hands .leftHand{
    17.     left:182px;
    18.     top:220px;
    19.     -webkit-transform:rotate(-40deg);
    20. }
    21. .hands .leftHand:after,
    22. .hands .rightHand:after{
    23.     content: '';
    24.     width: 6px;
    25.     border:3px solid #000;
    26.     border-radius: 3px;
    27.     position: absolute;
    28.     left:13px;
    29.     top:50px;
    30.     -webkit-transform:rotate(90deg);
    31. }
    32.  
    33. .hands .leftHand:after{
    34.     left:53px;
    35.     top:50px;
    36.     -webkit-transform:rotate(-90deg);

    效果圖如下:

    再接下來就是雙腳的部分了,主要就是鞋面的設(shè)計,我是通過一個矩形,然后設(shè)置不同的圓角值,加上一點點的旋轉(zhuǎn)來模擬的,這一塊的話,怎么做我都覺得不是很像,所以***差不多我就妥協(xié)了。

     
     
     
     
    1. .feet{
    2.     position: relative;
    3. }
    4. .feet .left_foot,
    5. .feet .right_foot{
    6.     width: 36px;
    7.     height: 50px;
    8.     border-bottom-right-radius: 6px;
    9.     border-bottom-left-radius: 9px;
    10.     background: #000;
    11.     position: absolute;
    12.     top: 406px;
    13.     left:88px;
    14.     -webkit-transform-origin: right top;
    15. }
    16. .feet .left_foot{
    17.     border-bottom-right-radius: 9px;
    18.     border-bottom-left-radius: 6px;
    19.     left:130px;
    20.     -webkit-transform-origin: left top;
    21. }
    22. .feet .left_foot:after,
    23. .feet .right_foot:after{
    24.     content: '';
    25.     width: 60px;
    26.     height: 35px;
    27.     border-radius: 20px 10px 21px 15px;
    28.     background: #000;
    29.     position: absolute;
    30.     left:-36px;
    31.     top:14.4px;
    32.     -webkit-transform:rotate(5deg);
    33. }
    34. .feet .left_foot:after{
    35.     border-radius: 10px 20px 15px 21px;
    36.     left:13px;
    37.     -webkit-transform:rotate(-5deg);

    效果圖如下:

    本來是不想畫頭發(fā)的,感覺怪難的,***嘗試了一下,還是能出個樣子,那就添加上去吧。原理跟褲子左右兩邊的實現(xiàn)原理是一樣的,只是參數(shù)值不一樣罷了,大家參考代碼琢磨一下:

     
     
     
     
    1. .hair{
    2.     position: relative;
    3. }
    4. .left_hair_one{
    5.     width: 130px;
    6.     height: 100px;
    7.     border-radius: 50%;
    8.     border-top:8px solid #000;
    9.     position: absolute;
    10.     left:17px;
    11.     top:-17px;
    12.     -webkit-transform:rotate(27deg);
    13. }
    14. .left_hair_two{
    15.     width: 80px;
    16.     height: 80px;
    17.     border-radius: 50%;
    18.     border-top:6px solid #000;
    19.     position: absolute;
    20.     left:45px;
    21.     top:-10px;
    22.     -webkit-transform:rotate(15deg);
    23. }
    24. 陰影部分:
    25. .groundShadow{
    26.     width: 200px;
    27.     height: 2px;
    28.     border-radius: 50%;
    29.     background: rgba(0,0,0,0.3);
    30.     box-shadow: 0 0 2px 4px rgba(0,0,0,0.3);
    31.     position: relative;
    32.     top: 455px;
    33.     left:25px;

    ***就是最初的效果了:

    這時大家可能會問:然后呢?不是還會動的嗎?

    是的,這里我就大概講一下實現(xiàn)的思路吧:

    1.頭發(fā):頭發(fā)我想實現(xiàn)的是被小風(fēng)輕輕地吹起來,然后很快就塌下去,所以吹起和下塌分配的時間很關(guān)鍵;

    2.眼睛:眼睛我設(shè)想的場景是小黃人在悠閑地走路,然后不時左右看一下兩邊的風(fēng)景,所以眼睛轉(zhuǎn)動很悠哉,所以分配的時間可以稍微長一點點;

    3.嘴巴:讓嘴巴動起來確實比較難,因為要動的話,遮罩也得實時跟著改變,而且不能露餡,所以***實現(xiàn)的是當(dāng)它往左邊看了一下之后賣了一下萌;

    4.雙手和雙腳:這部分確實很難逼真,本來腳就不是正常的走路狀態(tài),所以只能按卓別林老爺爺?shù)淖呗贩绞侥M一下,而且左右腳動作是緊接實現(xiàn)而不是同步實現(xiàn)。雙手的話,我是簡單模擬人在走路時有擺手的自然慣性,而且是左腳配右手,右腳配左手。考慮到它的雙手是放在背后的,所以我的擺動幅度設(shè)置為非常小,有效果但不明顯。

    OK,我就直接把動畫代碼放上來吧:

     
     
     
     
    1. .left_hair_one{
    2.     -webkit-animation: lefthair 2s ease-in-out infinite;
    3. }
    4. @-webkit-keyframes lefthair{
    5.     0%,25%,31%,100%{
    6.     }
    7.     30%{
    8.         -webkit-transform: rotate(31deg) translate3d(-3px,-1px,0);
    9.     }
    10. }
    11. .eyes .leftEye .left_blackEye,
    12. .eyes .rightEye .right_blackEye{
    13.     -webkit-animation: blackeye 5s ease-in infinite;
    14. }
    15. @-webkit-keyframes blackeye{
    16.     0%,20%,50%,70%,100%{
    17.         -webkit-transform: translateX(0px);
    18.     }
    19.     30%,40%{
    20.         -webkit-transform: translateX(15px);
    21.     }
    22.     80%,90%{
    23.         -webkit-transform: translateX(-15px);
    24.     }
    25. }
    26. .eyes .leftEye .left_blackEye .left_white,
    27. .eyes .rightEye .right_blackEye .right_white{
    28.     -webkit-animation: whiteeye 5s ease-in-out infinite;
    29. }
    30. @-webkit-keyframes whiteeye{
    31.     0%,20%,50%,70%,100%{
    32.         -webkit-transform: translateX(0px);
    33.     }
    34.     30%,40%{
    35.         -webkit-transform: translate3d(3px,4px,0);
    36.     }
    37.     80%,90%{
    38.         -webkit-transform: translate3d(-15px,4px,0);
    39.     }
    40. }
    41. .mouse .mouse_shape{
    42.     -webkit-animation: mouse 5s ease-in-out infinite;
    43. }
    44. @-webkit-keyframes mouse{
    45.     40%,43%{
    46.         width: 45px;
    47.         height: 25px;
    48.         top:180px;
    49.     }
    50.     0%,35%,48%,100%{
    51.         width: 55px;
    52.         height: 35px;
    53.         top:175px;
    54.         -webkit-transform:rotate(-35deg);
    55.  &n
      文章標(biāo)題:純CSS3畫出小黃人并實現(xiàn)動畫效果
      標(biāo)題來源:http://m.5511xx.com/article/djphjdg.html
    56. <sup id="uueen"><button id="uueen"><center id="uueen"></center></button></sup>