HTML 畫轉(zhuǎn)盤源代碼實現(xiàn)方法如下:
<!DOCTYPE html> <html> <head> <title>HTML 畫轉(zhuǎn)盤</title> <style> .spinner { width: 300px; height: 300px; border-radius: 50%; background-color: #f44336; overflow: hidden; position: relative; } .arrow { width: 5px; height: 100px; background-color: #fff; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(0deg); transform-origin: bottom; transition: transform 5s ease-out; } </style> </head> <body> <div class="spinner"> <div class="arrow"></div> </div> <script> function spin() { var arrow = document.querySelector('.arrow'); var rotate_degrees = Math.floor(Math.random() * 360); arrow.style.transform = 'translate(-50%, -50%) rotate(' + rotate_degrees + 'deg' + ')'; } setInterval(spin, 5000); </script> </body> </html>
上面的代碼通過HTML和CSS創(chuàng)建了一個紅色的圓形轉(zhuǎn)盤,在轉(zhuǎn)盤中央添加了一個白色的箭頭。JavaScript中的spin()函數(shù)用于旋轉(zhuǎn)箭頭,并將角度隨機化,以增加游戲性。setInterval()函數(shù)用于每隔5秒調(diào)用一次spin()函數(shù),從而使箭頭在隨機的角度上旋轉(zhuǎn)。