怎么用html5实现 抽奖效果

如题所述

这个需要用到H5新标签:canvas绘制图形,利用js来实现抽奖效果,实现步骤如下:
  var num = 6; // 奖品数量 var canvas = document.getElementById('canvas'); var
btn = document.getElementById('btn'); if(!canvas.getContext){
alert('抱歉!浏览器不支持。'); return; } // 获取绘图上下文 var ctx = canvas.getContext('2d'); for
(var i = 1; i <= num; i++) { // 保存当前状态 ctx.save(); // 开始一条新路径
ctx.beginPath(); // 位移到圆心,下面需要围绕圆心旋转 ctx.translate(150, 150); // 从(0,
0)坐标开始定义一条新的子路径 ctx.moveTo(0, 0); // 旋转弧度,需将角度转换为弧度,使用 degrees * Math.PI/180
公式进行计算。 ctx.rotate(360 / num * i * 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.restore(); }
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-10

做抽奖,用 Epub360!可视化编辑器,封装组件拼接,完成抽奖活动。

相似回答