CSS摩天輪是一種具有視覺沖擊力的網頁特效,可以通過CSS代碼實現。下面是一份基本的CSS摩天輪代碼樣例。
<div class="wheel"> <div class="wrapper"> <div class="item item-1"></div> <div class="item item-2"></div> <div class="item item-3"></div> <div class="item item-4"></div> <div class="item item-5"></div> <div class="item item-6"></div> <div class="item item-7"></div> <div class="item item-8"></div> <div class="item item-9"></div> </div> </div> <style> .wheel { height: 300px; width: 300px; position: relative; margin: 0 auto; transform: rotate(45deg); } .wrapper { height: 100%; width: 100%; position: absolute; top: 0; left: 0; animation: spin 15s linear infinite; transform-style: preserve-3d; animation-play-state: paused; } .item { height: 50%; width: 50%; position: absolute; top: 0; left: 0; transform-style: preserve-3d; } .item-1 { background-color: #ffa7c4; transform: translateZ(150px); } .item-2 { background-color: #ffdef3; transform: rotateY(40deg) translateZ(150px); } .item-3 { background-color: #fcf6b8; transform: rotateY(80deg) translateZ(150px); } .item-4 { background-color: #88d8b0; transform: rotateY(120deg) translateZ(150px); } .item-5 { background-color: #57c8f2; transform: rotateY(160deg) translateZ(150px); } .item-6 { background-color: #d19feb; transform: rotateY(200deg) translateZ(150px); } .item-7 { background-color: #fcd8a9; transform: rotateY(240deg) translateZ(150px); } .item-8 { background-color: #afcedc; transform: rotateY(280deg) translateZ(150px); } .item-9 { background-color: #b0c4d9; transform: rotateY(320deg) translateZ(150px); } @keyframes spin { from { transform: rotateY(0deg); } to { transform: rotateY(360deg); } } .wheel:hover .wrapper { animation-play-state: running; } </style>
上述代碼中,使用了transform屬性來實現3D效果,同時利用了CSS動畫和動態變化,讓摩天輪輪廓得以明顯展示。