CSS實(shí)現(xiàn)行星運(yùn)轉(zhuǎn)動畫
/* HTML */ <div class="sun"></div> <div class="planet mercury"></div> <div class="planet venus"></div> <div class="planet earth"></div> <div class="planet mars"></div> /* CSS */ .sun { width: 200px; height: 200px; border-radius: 50%; background: yellow; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px; animation: sun-rotate 10s linear infinite; } .planet { width: 50px; height: 50px; border-radius: 50%; position: absolute; animation-duration: 5s; animation-iteration-count: infinite; animation-timing-function: linear; } .mercury { left: 60%; top: 50%; margin-top: -25px; margin-left: -25px; border: 2px solid gray; animation-name: mercury-rotate; } .venus { left: 35%; top: 50%; margin-top: -25px; margin-left: -25px; background: orange; animation-name: venus-rotate; } .earth { left: 10%; top: 50%; margin-top: -25px; margin-left: -25px; background: blue; animation-name: earth-rotate; } .mars { left: 85%; top: 50%; margin-top: -25px; margin-left: -25px; background: red; animation-name: mars-rotate; } @keyframes sun-rotate { from { transform: rotate(0); } to { transform: rotate(360deg); } } @keyframes mercury-rotate { from { transform: rotate(0); } to { transform: rotate(360deg); } } @keyframes venus-rotate { from { transform: rotate(0); } to { transform: rotate(360deg); } } @keyframes earth-rotate { from { transform: rotate(0); } to { transform: rotate(360deg); } } @keyframes mars-rotate { from { transform: rotate(0); } to { transform: rotate(360deg); } }
以上是一個簡單的行星運(yùn)轉(zhuǎn)動畫的實(shí)現(xiàn)代碼,通過CSS3的旋轉(zhuǎn)動畫效果,實(shí)現(xiàn)了太陽和行星圍繞自身中心旋轉(zhuǎn)的效果。CSS3動畫效果開發(fā)越來越火熱,動畫效果酷炫,實(shí)現(xiàn)方便。