生成一个转盘抽奖的网页代码
时间: 2024-01-18 09:03:34 浏览: 142
html网页大转盘抽奖页面代码
<!DOCTYPE html>
<html>
<head>
<title>转盘抽奖</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
#roulette {
width: 300px;
height: 300px;
position: relative;
margin: 0 auto;
background-image: url('roulette.png');
background-size: cover;
border-radius: 50%;
overflow: hidden;
}
#pointer {
width: 20%;
height: 30%;
position: absolute;
top: 35%;
left: 40%;
background-color: red;
transform-origin: bottom center;
transform: rotate(-45deg);
border-radius: 50% 50% 0 0;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
cursor: pointer;
}
.prize {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-color: rgba(255, 255, 255, 0.8);
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
font-weight: bold;
text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 1s ease-in-out;
border-radius: 50%;
}
.prize.show {
opacity: 1;
}
</style>
</head>
<body>
<div id="roulette">
<div id="pointer"></div>
<div class="prize" style="transform: rotate(0deg);">一等奖</div>
<div class="prize" style="transform: rotate(45deg);">二等奖</div>
<div class="prize" style="transform: rotate(90deg);">三等奖</div>
<div class="prize" style="transform: rotate(135deg);">四等奖</div>
<div class="prize" style="transform: rotate(180deg);">五等奖</div>
<div class="prize" style="transform: rotate(225deg);">六等奖</div>
<div class="prize" style="transform: rotate(270deg);">七等奖</div>
<div class="prize" style="transform: rotate(315deg);">八等奖</div>
</div>
<script type="text/javascript">
var pointer = document.getElementById('pointer');
var prizes = document.getElementsByClassName('prize');
var deg = 0;
var speed = 0;
var timer = null;
var maxSpeed = 30;
var minSpeed = 1;
function start() {
clearInterval(timer);
speed = minSpeed;
timer = setInterval(function() {
if (speed < maxSpeed) {
speed += 1;
}
deg += speed;
deg %= 360;
pointer.style.transform = 'rotate(' + deg + 'deg)';
for (var i = 0; i < prizes.length; i++) {
var prize = prizes[i];
var prizeDeg = prize.style.transform.match(/\d+/g);
prizeDeg = prizeDeg ? parseInt(prizeDeg[0]) : 0;
if (deg >= prizeDeg && deg < prizeDeg + 45) {
prize.classList.add('show');
} else {
prize.classList.remove('show');
}
}
}, 30);
}
pointer.addEventListener('click', function() {
start();
});
</script>
</body>
</html>
阅读全文