按下右側的「點擊預覽」按鈕能夠在當前頁面預覽,點擊連接能夠全屏預覽。css
https://codepen.io/comehope/pen/xzYVzOhtml
此視頻是能夠交互的,你能夠隨時暫停視頻,編輯視頻中的代碼。前端
請用 chrome, safari, edge 打開觀看。git
https://scrimba.com/p/pEgDAM/cRkRLsmgithub
每日前端實戰系列的所有源代碼請從 github 下載:chrome
https://github.com/comehope/front-end-daily-challengesdom
定義 dom,容器中包含 2 個元素:flex
<div class="eyes"> <span class="left"></span> <span class="right"></span> </div>
居中顯示:動畫
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: black; }
定義容器尺寸:spa
.eyes { width: 40em; height: 10em; font-size: 10px; }
畫出眼睛的輪廓:
.eyes { position: relative; } .eyes > * { box-sizing: border-box; position: absolute; width: 15em; height: 10em; border: solid white; } .eyes .left { left: 0; } .eyes .right { right: 0; }
畫出眼球:
.eyes > * { border-width: 0 5em; } .eyes .left { border-radius: 50% 0; } .eyes .right { border-radius: 0 50%; }
使雙眼向內聚攏:
.eyes .left { transform: rotate(25deg); } .eyes .right { transform: rotate(-25deg); }
定義眨眼的動畫:
@keyframes blink { 40%, 60% { border-width: 0 5em; } 50% { border-width: 0 7.5em; } }
最後,把動畫效果應用到兩隻眼睛上:
.eyes > * { animation: blink 2s linear infinite; }
大功告成!