為什麼要做載入
我是如何做的
開始入門
·
·
·
·
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!doctype html> <html> <head> <!-- <link rel="preload"> for CSS, JS, and font files --> <style type="text/css"> /* * All the CSS for the loader * Minified and vendor prefixed */ </style> </head> <body> <div class="loader"> <!-- HTML for the loader --> </div> <header /> <main /> <footer /> <!-- Tags for CSS and JS files --> </body> </html> |
構建 logo 本身
JavaScript
1 2 3 4 5 | <div class="logo"> <div class="white"></div> <div class="orange"></div> <div class="red"></div> </div> |
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | .logo { position: relative; width: 100px; height: 100px; border: 4px solid black; box-sizing: border-box; background-color: white;
& > div { position: absolute; }
.red { top: 0; bottom: 0; left: 0; width: 27%; border-right: 4px solid black; background-color: #EA5664; } /* Similar code for div.orange and div.white */ } |
logo 的效果圖如下
邊框動畫
CSS 不允許我們直接對 div.logo 的邊框進行設定達到我們想要的效果, 所以我們必須
, 讓 div.logo::after 絕對定位 div.logo 的右下角, 代表方塊的下邊框和左邊框
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | .logo { position: relative; width: 100px; height: 100px; box-sizing: border-box; background-color: white;
&::before, &::after { content: ''; position: absolute; width: 100%; height: 100%; box-sizing: border-box; border: 4px solid transparent; }
&::before { top: 0; left: 0; border-top-color: black; border-right-color: black; }
&::after { bottom: 0; right: 0; border-bottom-color: red; // Red for demo purposes only border-left-color: red; } } |
height 調整到 100%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | div.logo { &::before, &::after { /* ... */ animation-timing-function: linear; } &::before { /* ... */ animation: border-before 1.5s infinite; animation-direction: alternate; } } @keyframes border-before { 0% { width: 0; height: 0; border-right-color: transparent; } 24.99% { border-right-color: transparent; } 25% { height: 0; width: 100%; border-right-color: black; } 50%, 100% { width: 100%; height: 100%; } } |
方塊動畫
· 0 to 25%
· 25 to 50%
· 50 to 65%
· 65 to 80%
· 75 to 90%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | @keyframes red { 0%, 50% { width: 0; opacity: 0; } 50.01% { opacity: 1; } 65%, 100% { width: 27%; opacity: 1; } } |