按下右側的「點擊預覽」按鈕能夠在當前頁面預覽,點擊連接能夠全屏預覽。css
https://codepen.io/comehope/pen/YvYVvYhtml
此視頻是能夠交互的,你能夠隨時暫停視頻,編輯視頻中的代碼。前端
請用 chrome, safari, edge 打開觀看。git
https://scrimba.com/p/pEgDAM/cN6L9SZgithub
每日前端實戰系列的所有源代碼請從 github 下載:chrome
https://github.com/comehope/front-end-daily-challengesdom
定義 dom,容器中包含 6 個段落,每一個段落 1 行代碼:佈局
<div class="code"> <p>function repeat() {</p> <p> eat();</p> <p> sleep();</p> <p> code();</p> <p> repeat();</p> <p>}</p> </div>
居中顯示:flex
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; }
代碼佈局:動畫
.code { background-color: silver; padding: 1em 0; font-size: 24px; font-family: monospace; border-radius: 0.5em; } .code p { white-space: pre; padding: 0 1em; margin: 0.5em; }
定義動畫:
.code p:not(:last-child) { animation: step 2s infinite; } @keyframes step { 0%, 25% { color: white; background-color: dodgerblue; } 26%, 100% { color: black; background-color: transparent; } }
設置動畫延時,描述單步執行的場景:
.code p:not(:last-child) { animation-delay: var(--d); } .code p:nth-child(2) { --d: 0s; } .code p:nth-child(3) { --d: 0.5s; } .code p:nth-child(4) { --d: 1s; } .code p:nth-child(1), .code p:nth-child(5) { --d: 1.5s; }
大功告成!