css小貓笑起來的動畫

_小田發表於2018-06-05

No.3 - CSS transition 和 CSS transform 配合製作動畫

倉庫地址

預覽地址

資料

文章地址

其實文章地址裡面提供的資料已經很不錯了!!!(偷懶~

效果

截圖

截圖

程式碼實現

# html
<div class="container">
  <!-- 臉 -->
  <div class="face">
    <!-- 頭髮 -->
    <div class="hair"></div>
    <!-- 眼睛 -->
    <div class="eye-wrap">
      <div class="eye left">
        <div class="eye-circle">
          <div class="eye-core"></div>
        </div>
        <div class="eye-bottom"></div>
        <div class="face-red"></div>
      </div>
      <div class="eye right">
        <div class="eye-circle">
          <div class="eye-core"></div>
        </div>
        <div class="eye-bottom"></div>
        <div class="face-red"></div>
      </div>
    </div>
    <!-- 鼻子 -->
    <div class="nose"></div>
    <!-- 嘴巴 -->
    <div class="mouth-wrap">
      <div class="mouth left"></div>
      <div class="mouth right"></div>
    </div>
  </div>
  <!-- 耳朵 -->
  <div class="ear-wrap">
    <div class="ear left"></div>
    <div class="ear right"></div>
  </div>
</div>
複製程式碼
# css 動畫部分樣式
.face,
.hair,
.face-red,
.eye-bottom,
.ear,
.eye-core,
.mouth{
    transition: transform 1s;    
}
.face-red{
    transition: opacity 1s;
}
.mouth{
    transition: border-radius 1s;
}

.face:hover~.ear-wrap .left{
    transform-origin: 50%, 100%;
    transform: rotate(-30deg);
}
.face:hover~.ear-wrap .right{
    transform-origin: 50%, 100%;
    transform: rotate(30deg);
}
.face:hover .eye-wrap .eye-bottom{
    transform: translateY(-15px);
}

.face:hover .eye-wrap .face-red{
    opacity: 1;
}
.face:hover .eye-wrap .eye-core{
    transform: scaleX(.8);
}
.face:hover .mouth-wrap .left{
    border-radius: 0% 40% 50% 50%;
}
.face:hover .mouth-wrap .right{
    border-radius: 0% 40% 50% 50%;
}
.face:hover{
    transform: scaleX(.99);
    transform: translateY(-6px);
}
.face:hover .hair{
    transform: scaleX(.9);
}
複製程式碼

Qq: 952822399

相關文章