深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 327|回复: 0
打印 上一主题 下一主题

转盘抽奖范例

[复制链接]

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
跳转到指定楼层
楼主
发表于 2022-8-19 23:01:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>无标题文档</title>

  6. <style type="text/css">
  7.    *{ padding:0; margin:0}
  8.    #can{ background:#F2F2F2}
  9. </style>

  10. <body>
  11.      <canvas id="can" width="800" height="800"></canvas>
  12. </body>

  13. <script>
  14. zpFun();
  15. function  zpFun(){
  16.      
  17.      
  18.      var canid=document.getElementById("can");
  19.      var  cans=canid.getContext("2d");
  20.      var  deg=Math.PI/180;
  21.      var colorArr=["#6D7278","#B55610","#349933","#CC3333","#2C3144","#B12E3D","#FFE44C","#41547F"];
  22.      var textArr=["javascript","photoshop","css3","html5","mysql","php","java","dreamweaver"];
  23.      var arg=0;
  24.      var step=50+50*Math.random();

  25.      cans.translate(300,350);
  26.      //cans.strokeStyle="#000000";
  27.      
  28.      var t=setInterval(function(){   
  29.          
  30.              step*=0.95;
  31.             
  32.              if(step<=0.2){
  33.                      
  34.                  clearInterval(t);
  35.                  var snum=Math.ceil(arg/45);
  36.                  var con=textArr[textArr.length-snum];
  37.                  
  38.                  
  39.                  //cans.beginPath();
  40.                  //cans.font="14px 微软雅黑";
  41.                  //cans.textAlign="center";
  42.                  //cans.fillText(textArr[textArr.length-snum],0,0);
  43.                  cans.font="20px Arial";   
  44.                  cans.fillStyle="#cc0000";
  45.                  cans.textAlign="center";        
  46.                  cans.fillText(con,0,0);
  47.                  return;
  48.                  
  49.              }else{
  50.                  
  51.                  if(arg>=360){
  52.                      
  53.                     arg=0;   
  54.                      
  55.                  }
  56.                  
  57.                  
  58.             }
  59.             

  60.              arg=arg+step;
  61.          
  62.               cans.clearRect(-500,-500,1300,1300);
  63.              //画指针
  64.              cans.beginPath();
  65.              cans.lineWidth=10;
  66.              cans.moveTo(230,0);
  67.              cans.lineTo(300,0);
  68.              cans.stroke();
  69.             
  70.             
  71.      
  72.              //    //画扇形
  73.             
  74.              cans.save();
  75.              cans.rotate(arg*deg);
  76.              cans.lineWidth=1;
  77.             
  78.             
  79.              for(var i=0;i<8;i++){
  80.                      cans.beginPath();
  81.                      cans.fillStyle=colorArr[i];
  82.                      cans.moveTo(0,0);
  83.                      cans.arc(0,0,200,i*45*deg,(i+1)*45*deg);
  84.                      cans.closePath();
  85.                      cans.fill();
  86.                      cans.stroke();
  87.              }
  88.              //    //画中心园
  89.              cans.beginPath();
  90.              cans.fillStyle="#ffffff";
  91.              cans.arc(0,0,50,0,360*deg);
  92.              cans.fill();
  93.             
  94.              //写文字
  95.              for(var i=0;i<8;i++){
  96.              cans.save();
  97.              cans.beginPath();
  98.              cans.rotate((i*45+25)*deg);
  99.              cans.font="20px Arial";
  100.              cans.fillText(textArr[i],70,0);
  101.              cans.restore();
  102.             
  103.              }
  104.              cans.restore();
  105.      
  106. },60);        
  107.      
  108.      
  109.      
  110. }


  111. </script>

  112. </html>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 00:22 , Processed in 0.038419 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表