注意 @keyframes to/from 的學習
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <style> /* 順時針自轉 */ @keyframes spin { to { transform: rotate(1turn); } } /* 逆時針自轉 */ @keyframes spin-reverse { from { transform: rotate(1turn); } } /* 這是一坨自暴自棄的樣式 */ .basic{ border:3px solid orange; height: 150px; width:150px; border-radius:50%; margin:50px; } /* 順時針自轉,同時該元素下所有的子元素也會一起旋轉起來 */ .avatar{ /* linear : 從頭到尾速度是相同的; infinite:無限輪播 */ animation: spin 10s infinite linear; } /* 逆時針旋轉“自轉”,與“公轉”導致的旋轉相抵消。形成一種不動的錯覺 */ .avatar > img { animation:spin-reverse 10s infinite linear; } </style> <div class="basic avatar"> <img src="github.png" alt=""> </div> </body> </html>