用html实现刮刮卡效果

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
	/* *{
		margin: 0;
		padding: 0;
	} */
	#cvs{
		border: 1px solid red;
		position: absolute;
		z-index: 999;
	}
	#con{
		width:200px ;
		height: 100px;
		text-align: center;
		line-height: 100px;
		font-size: 20px;
		position: absolute;
	}
</style>
</head>
<body>
	<canvas id="cvs" width="200" height="100"></canvas>
	<div id="con"></div>
</body>
<script type="text/javascript">
		var cvs=document.getElementById('cvs');
		var con=document.getElementById("con")
		var ctx=cvs.getContext('2d');
		var arr=[
			"笔记本电脑",
			"iphone 11",
			"mac pro",
			"汤臣一品",
			"谢谢惠顾",
			"一百万"
		]
		var index=Math.floor(Math.random()*arr.length) 
		con.innerHTML=arr[index]
		ctx.beginPath();
		ctx.rect(0,0,cvs.width,cvs.height);
		ctx.fillStyle='#ccc';
		ctx.fill();
		ctx.closePath()
	
	cvs.onmousedown=function(){
		document.onmousemove=function(e){
			ctx.clearRect(e.clientX-cvs.offsetLeft,e.clientY-cvs.offsetTop,20,20)
		}
		document.onmouseup=function(){
			document.onmousedown=null;
			document.onmousemove=null;
		}
	}
	
	
</script>
</html>
发布了15 篇原创文章 · 获赞 3 · 访问量 659

猜你喜欢

转载自blog.csdn.net/qq_42714690/article/details/103779590