今天自主性地写了一个鼠标事件控制canvas绘制矩形的demo. 感觉通过自己的思路写的demo是蛮好的, 虽然只是60行来代码. 得到了朋友的简单夸奖, 我也很开心, 这个demo肯定是有不足之处的. 望大家多多指教.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="小白学习中" content="小白">
<title>不为什么,只是我喜欢</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
html, body {
width: 100%;
height: 100%;
}
/*canvas {
width: 100%;
height: 100%;
}*/
</style>
</head>
<body>
<canvas width="1000" height="500"></canvas>
<script>
let myCanvas = document.querySelector('canvas');
let isPoint = true;
let arr = [];
let temp = [];
function paint(ctx, startX, startY, x, y) {
// ctx = ctx || docu