按下右側的「點擊預覽」按鈕能夠在當前頁面預覽,點擊連接能夠全屏預覽。css
https://codepen.io/comehope/pen/ERwpeGhtml
此視頻是能夠交互的,你能夠隨時暫停視頻,編輯視頻中的代碼。前端
請用 chrome, safari, edge 打開觀看。git
https://scrimba.com/p/pEgDAM/cED8KsKgithub
每日前端實戰系列的所有源代碼請從 github 下載:chrome
https://github.com/comehope/front-end-daily-challengesdom
定義 dom,容器是包含 7 個子元素,每一個子元素中有一個字母:flex
<div class="loader"> <span>l</span> <span>o</span> <span>a</span> <span>d</span> <span>i</span> <span>n</span> <span>g</span> </div>
居中顯示:動畫
body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; background-color: black; }
設置容器尺寸:spa
.loader { width: 40em; height: 3em; }
設置文字樣式:
.loader { color: dodgerblue; font-size: 1.5em; text-transform: uppercase; font-family: sans-serif; }
給文字增長漸隱漸顯動畫:
.loader span { animation: moving 2s linear infinite; } @keyframes moving { 0% { filter: opacity(0); } 33% { filter: opacity(1); } 66% { filter: opacity(1); } 100% { filter: opacity(0); } }
設置動畫延時,加強動畫效果:
.loader span { animation-delay: calc((var(--n) - 10) * 0.2s) } .loader span:nth-child(1) { --n: 1; } .loader span:nth-child(2) { --n: 2; } .loader span:nth-child(3) { --n: 3; } .loader span:nth-child(4) { --n: 4; } .loader span:nth-child(5) { --n: 5; } .loader span:nth-child(6) { --n: 6; } .loader span:nth-child(7) { --n: 7; }
設置文字旋轉效果:
.loader { position: relative; } .loader span { position: absolute; height: 3em; } @keyframes moving { 0% { filter: opacity(0); transform: rotate(-180deg); } 33% { filter: opacity(1); transform: rotate(0deg); } 66% { filter: opacity(1); transform: rotate(0deg); } 100% { filter: opacity(0); transform: rotate(180deg); } }
增長文字移動的效果:
@keyframes moving { 0% { filter: opacity(0); transform: rotate(-180deg); left: 100%; } 33% { filter: opacity(1); transform: rotate(0deg); left: 60%; } 66% { filter: opacity(1); transform: rotate(0deg); left: 40%; } 100% { filter: opacity(0); transform: rotate(180deg); left: 0; } }
增長文字變色效果:
.loader { animation: change-color 10s linear infinite; } @keyframes change-color { 0% { color: dodgerblue; } 20% { color: hotpink; } 40% { color: gold; } 60% { color: mediumpurple; } 80% { color: lightgreen; } 100% { color: dodgerblue; } }
最後,把可能出如今頁面外的部分隱藏掉:
body { overflow: hidden; }
大功告成!