轉盤抽獎是一種常見的網站游戲。要實現它的動態效果需要使用CSS。下面是一份基本的轉盤抽獎CSS代碼。
/* 設置轉盤大小及樣式 */ .turntable { position: relative; width: 500px; height: 500px; background-color: #ccc; border-radius: 50%; overflow: hidden; } /* 設置轉盤抽獎區域 */ .lottery-area { position: absolute; top: 0; left: 0; display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; text-align: center; } /* 設置抽獎按鈕 */ .lottery-btn { position: absolute; bottom: 50px; left: calc(50% - 60px); width: 120px; height: 40px; background-color: #fff; border-radius: 20px; cursor: pointer; z-index: 1; display: flex; justify-content: center; align-items: center; text-align: center; } /* 設置獎品區塊 */ .prize-list { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transform-origin: 50% 50%; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; } /* 設置每個獎品區塊的樣式 */ .prize { position: relative; width: 100px; height: 100px; margin: 20px; background-color: #fff; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 20px; } /* 設置每個獎品區塊的中心點位置 */ .prize:nth-child(1) { transform: rotate(0deg) translate(250px) rotate(0deg); } .prize:nth-child(2) { transform: rotate(45deg) translate(250px) rotate(-45deg); } .prize:nth-child(3) { transform: rotate(90deg) translate(250px) rotate(-90deg); } .prize:nth-child(4) { transform: rotate(135deg) translate(250px) rotate(-135deg); } .prize:nth-child(5) { transform: rotate(180deg) translate(250px) rotate(-180deg); } .prize:nth-child(6) { transform: rotate(225deg) translate(250px) rotate(-225deg); } .prize:nth-child(7) { transform: rotate(270deg) translate(250px) rotate(-270deg); } .prize:nth-child(8) { transform: rotate(315deg) translate(250px) rotate(-315deg); }
通過以上代碼,即可實現一個簡單的轉盤抽獎功能,讓用戶們輕松愉快地玩耍。