rouletteWheel是抽奖转盘组件,原生js,压缩仅9kb
无
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
new RouletteWheel({
centerX: canvas.width / 2,
centerY: canvas.height / 2,
outsideRadius: 200,
awards: [
{ content: 'iphone8' },
{ content: '大保健' },
{ content: '10元话费' },
{ content: '现金30', img: './img/3.png' },
{ content: '30元话费' },
{ content: '优惠券', img: './img/1.png' },
{ content: '100元话费' },
{ type: 'losing', content: '谢谢参与', img: './img/4.png' }
],
finish: function (index) {
switch (this.awards[index].type) {
case 'losing':
alert('💔很遗憾,您没有中奖~');
break;
default:
alert('🎉恭喜您中得:' + this.awards[index].content);
break;
}
}
}).render(canvas, context);
更多配置和用法,请参考examples和源码