canvas绘图
<canvas id="tetris" width="1800" height="900"></canvas> <script type="text/javascript"> var canvas = document.getElementById("tetris"); var context = canvas.getContext("2d"); var isDown = false; var prePoint = null; context.strokeStyle="#ea7421"; context.lineWidth = 5; context.lineCap = 'round'; canvas.onmousedown = function(){ isDown = true; }; canvas.onmouseup = function(){ isDown = false; prePoint = null; } canvas.onmousemove = function(e){ if(isDown){ context.beginPath(); if(!prePoint){ prePoint = { x: e.clientX, y: e.clientY }; }else{ context.moveTo(prePoint.x, prePoint.y); prePoint = { x: e.clientX, y: e.clientY }; context.lineTo(prePoint.x, prePoint.y); context.stroke(); context.closePath(); } } } canvas.onclick = function(e){ context.beginPath(); context.moveTo(e.clientX-1, e.clientY); context.lineTo(e.clientX, e.clientY); context.stroke(); context.closePath(); }; </script>
相关推荐
jinxiutong 2020-07-26
northwindx 2020-05-31
jinxiutong 2020-05-10
大地飞鸿 2020-11-12
星星有所不知 2020-10-12
MIKUScallion 2020-07-05
songfens 2020-07-05
songfens 2020-06-11
songfens 2020-06-08
northwindx 2020-05-31
northwindx 2020-05-27
northwindx 2020-05-25
MIKUScallion 2020-05-25
xdyangxiaoromg 2020-05-10
大地飞鸿 2020-05-06
northwindx 2020-04-25