console
window.addEventListener('load', function(){
var num = 6;
if (num % 2 !== 0){
alert('请配置偶数奖项');
}
var canvas = document.getElementById('canvas');
var btn = document.getElementById('btn');
if(!canvas.getContext){
alert('抱歉!浏览器不支持。');
return;
}
var ctx = canvas.getContext('2d');
for (var i = 0; i < num; i++) {
ctx.save();
ctx.beginPath();
ctx.translate(150, 150);
ctx.moveTo(0, 0);
ctx.rotate((360 / num * i + 360 / num / 2) * Math.PI/180);
ctx.arc(0, 0, 150, 0, 2 * Math.PI / num, false);
if (i % 2 == 0) {
ctx.fillStyle = '#ffb820';
}else{
ctx.fillStyle = '#ffcb3f';
}
ctx.fill();
ctx.lineWidth = 0.5;
ctx.strokeStyle = '#f48d24';
ctx.stroke();
ctx.fillStyle = '#fff';
ctx.font="16px sans-serif";
ctx.fillText(i + 1, 100, 60);
ctx.restore();
}
btn.onclick = function(){
canvas.style.transform = 'rotate(1800deg)';
}
}, false);
<div id="turntable">
<canvas id="canvas" width="300" height="300">抱歉!浏览器不支持。</canvas>
<a id="btn" href="javascript:;">抽奖</a>
</div>
#turntable{
position: relative;
}
#canvas{
-webkit-transform: all 6s ease;
transition: all 6s ease;
}
#btn{
position: absolute;
left: 120px;
top: 120px;
width: 60px;
height: 60px;
border-radius: 50%;
background-color: #fff;
line-height: 60px;
text-align: center;
}
#btn:after{
position: absolute;
display: block;
content: '';
left: 10px;
top: -32px;
width: 0;
height: 0;
overflow: hidden;
border-width: 20px;
border-style: solid;
border-color: transparent;
border-bottom-color: #fff;
}