当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 刮刮乐效果

刮刮乐效果

2018年09月29日  | 移动技术网IT编程  | 我要评论

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>刮刮卡</title>
<style>
*{
margin: 0;
padding: 0;
}
img{
width: 400px;
height: 300px;
position: absolute;
left: 200px;
z-index: -1;
}
canvas{
margin-left: 200px;
}
</style>
</head>
<body>

<img src="img/gailun.jpg" alt="">
<canvas id="canvas" width="400" height="300"></canvas>

<script>
var canvas = document.getelementbyid("canvas");
var context = canvas.getcontext('2d');
//画蒙布
context.beginpath();
context.fillstyle= 'grey'
context.fillrect(0,0,400,300);
//鼠标按下开刮
canvas.onmousedown=function(){
canvas.onmousemove = function(){
//获取鼠标坐标
var x = event.clientx;
var y = event.clienty;
//destination-out 显示原来的不在后来区域的部分
context.globalcompositeoperation = "destination-out";
context.beginpath();
context.arc(x-200,y,30,0,math.pi*2);
context.fill();
}
}
//鼠标抬起不刮开
canvas.onmouseup=function(){
canvas.onmousemove = function(){
}
}
</script>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网