0
点赞
收藏
分享

微信扫一扫

canvas 刮刮乐

有态度的萌狮子 2022-03-30 阅读 40
htmlcss2d




<!DOCTYPE html>


<html>


<head>


<meta charset="UTF-8">


<title></title>


<style type="text/css">


img{width: 500px;height: 500px;}


#myCanvas{margin-left: -503px;}


</style>


</head>


<body>


<img src="img/1.png" alt="" />


<canvas id="myCanvas" width="500" height="500">sorry</canvas>


</body>


<script type="text/javascript">


var myCanvas = document.getElementById("myCanvas");


var ctx = myCanvas.getContext('2d');




ctx.fillStyle = 'lightgray';


ctx.fillRect(0,0,myCanvas.width,myCanvas.height);






ctx.globalCompositeOperation = 'destination-out';




myCanvas.onmousedown = function(){


document.onmousemove = function(e){


var x = e.clientX -10;


var y = e.clientY -10;




ctx.beginPath();


ctx.fillStyle = 'red';


ctx.arc(x,y,10,0,Math.PI*2,true);


ctx.fill();


ctx.closePath();


}


}








</script>


</html>




<!DOCTYPE html>


<html>


<head>


<meta charset="UTF-8">


<title></title>


<style type="text/css">


img{width: 500px;height: 500px;}


#myCanvas{margin-left: -503px;}


</style>


</head>


<body>


<img src="img/1.png" alt="" />


<canvas id="myCanvas" width="500" height="500">sorry</canvas>


</body>


<script type="text/javascript">


var myCanvas = document.getElementById("myCanvas");


var ctx = myCanvas.getContext('2d');




ctx.fillStyle = 'lightgray';


ctx.fillRect(0,0,myCanvas.width,myCanvas.height);






ctx.globalCompositeOperation = 'destination-out';




myCanvas.onmousedown = function(){


document.onmousemove = function(e){


var x = e.clientX -10;


var y = e.clientY -10;




ctx.beginPath();


ctx.fillStyle = 'red';


ctx.arc(x,y,10,0,Math.PI*2,true);


ctx.fill();


ctx.closePath();


}


}








</script>


</html>



举报

相关推荐

0 条评论