Canvas系列之刮刮乐

看到几个朋友在玩刮刮乐,刚好最近在看canvas,就想着做一个刮刮乐,奖额自己定,想中多少就多少,是不是很嗨皮呢。。。。。。。当然,彩票虽好,但不要贪杯哦。。。。好的,言归正传,开始绘制了

绘制之前我们看看效果图:

guaguale

一点简单地结构

1
2
3
4
5
6
7
8
<div class="box">
<h2>刮 刮 乐</h2>
<div class="jiang"></div>
<div class="prize">
<div class="content">500万</div>
<canvas id="canvas" width="300" height="200"></canvas>
</div>
</div>

再来一斤的样式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.box{
margin: 60px 100px;
width:300px;
height:500px;
border:1px solid red;
background:rgba(255,0,0,.8);
}
h2{
text-align: center;
font-size: 30px;
color:cyan;
}
.jiang{
width:200px;
height: 200px;
border-radius: 50%;
background-color:rgba(255,0,0,.3);
line-height: 200px;
text-align: center;
font-size: 60px;
color:gold;
margin:20px auto;
}
.prize{
height:200px;
position: relative;
}
.content{
width:300px;
height: 200px;
background-color:rgba(0,0,255,0.1);
line-height: 200px;
text-align: center;
font-size: 60px;
color:purple;
margin:20px auto;
}
#canvas{
position:absolute;
top: 0;
left: 0;
cursor: url('xpc.cur'),pointer;
}

相信大家看到这个设置了

cursor: url('xpc.cur'),pointer;
改变光标的样式

光标样式可以任你设置,但是也可以自定义设置哦,设置一个你喜欢的图案,用url引进去,后面加一个pointer,当然了,浏览器兼容图片的样式不同的,你要小心了。。。。。。这里我用的是.xpc格式的 png jpg 。。。。。。

好了,把剩余的都拿走把

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var canvas=document.querySelector('#canvas')
var ctx=canvas.getContext('2d')
ctx.fillStyle='lightgray'
ctx.fillRect(0,0,300,200)
ctx.save()
ctx.font='30px serif'
ctx.fillStyle='black'
ctx.fillText('刮奖区',100,60)
ctx.save()
ctx.font='50px serif'
ctx.strokeStyle='red'
ctx.strokeText('大吉大利',50,150)
canvas.onmousedown=function(){
window.onmousemove=function(event){
ctx.clearRect(event.offsetX,event.offsetY,20,20);
}
}
canvas.onmouseup = function(){
window.onmousemove=function(){}
}

祝君,下次玩刮刮乐中大奖!

很惭愧<br><br>只做了一点微小的工作<br>谢谢大家