css3实现抽奖装盘效果

演示如下:



代码如下:

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="UTF-8">
<title>无标题文档</title>
<style>
   #main{
    display: block;
    padding:30px;
   }

   #triangle{
    position: absolute;
    left: 78px;
    top: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 20px solid blue;
   }

   canvas{
    transition: all 3s;
   }

   #tip{
    font-size: 30px;
    color: blue;
    margin:15px 0; 
   }

   #result{
    font-size: 30px;
    color: red;
    margin:15px 0; 
   }
</style>
</head>    
<body>
<div id="main">
   <div id="triangle"></div>
   <canvas id="mycanvas" width="100" height="100"></canvas>
   <div id="tip">点击装盘开始抽奖</div>
   <div id="result"></div>
</div>
<script type="text/javascript">
  var canvas=document.getElementById('mycanvas');
  var ctx=canvas.getContext('2d');
  ctx.fillStyle="red";
  ctx.arc(50,50,50,0,2*Math.PI);
  ctx.fill();
  ctx.beginPath();
  ctx.moveTo(50,0);
  ctx.lineTo(50,100);
  ctx.moveTo(0,50);
  ctx.lineTo(100,50);
  ctx.stroke();
  ctx.closePath();
  ctx.fillStyle="black";
  ctx.font="14px Georgia";
  ctx.fillText("手机",20,30);
  ctx.fillText("电脑",60,30);
  ctx.fillText("美女",20,70);
  ctx.fillText("汽车",60,70);

  var result=document.getElementById('result');
  canvas.οnclick=function(){
     var deg=Math.random()*360+720;
     canvas.style.transform="rotate("+deg+"deg)";
     setTimeout(showResult,3100);
     function showResult(){
      if(deg-720<90){
        result.innerHTML="恭喜你抽到了手机";
      }else if(deg-720>=90&°-720<180){
        result.innerHTML="恭喜你抽到了美女";
      }else if(deg-720>=180&°-720<270){
        result.innerHTML="恭喜你抽到了汽车";
      }else if(deg-720>=270){
        result.innerHTML="恭喜你抽到了电脑";
      }
    }
  }

</script>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值