按下右側的「點擊預覽」按鈕能夠在當前頁面預覽,點擊連接能夠全屏預覽。css
https://codepen.io/comehope/pen/JvmBdEhtml
此視頻是能夠交互的,你能夠隨時暫停視頻,編輯視頻中的代碼。前端
請用 chrome, safari, edge 打開觀看。git
https://scrimba.com/p/pEgDAM/cp2edUDgithub
每日前端實戰系列的所有源代碼請從 github 下載:chrome
https://github.com/comehope/front-end-daily-challengesdom
定義 dom,容器中包含一行文本和3條作海浪特效的 <span>:flex
<div class="sea"> <p class="title">the sea</p> <span class="wave"></span> <span class="wave"></span> <span class="wave"></span> </div>
居中顯示:動畫
html, body { height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(antiquewhite, navajowhite); }
設置容器樣式:spa
.sea { width: 300px; height: 300px; background-color: whitesmoke; background-image: linear-gradient( darkblue, rgba(255, 255, 255, 0) 80%, rgba(255, 255, 255, 0.5)); border-radius: 5px; box-shadow: 0 2px 30px rgba(0, 0, 0, 0.2); }
設置文字樣式:
.sea { position: relative; } .sea .title { color: white; font-size: 24px; font-family: serif; text-align: center; line-height: 250px; text-transform: uppercase; letter-spacing: 0.4em; position: absolute; z-index: 1; width: 100%; }
製做海浪動畫效果:
.sea .wave { position: absolute; top: -250px; left: -100px; width: 500px; height: 500px; background: deepskyblue; border-radius: 43%; filter: opacity(0.4); animation: drift linear infinite; } .sea .wave:nth-of-type(1) { animation-duration: 5s; } .sea .wave:nth-of-type(2) { animation-duration: 7s; } .sea .wave:nth-of-type(3) { animation-duration: 9s; } @keyframes drift { from { transform: rotate(360deg); } }
加大海浪的波動幅度,增長顏色差別:
.sea .wave { transform-origin: 50% 48%; } .sea .wave:nth-of-type(3) { background-color: orangered; filter: opacity(0.1); }
最後,隱藏容器外的內容:
.sea { overflow: hidden; }
大功告成!