<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>canvas3</title>
<script>
window.onload = function () {
var cv = document.getElementById("cv");
var ctx = cv.getContext('2d');
cv.onmousedown = function (ev) {
var ev = ev || window.event;
ctx.moveTo(ev.clientX - cv.offsetLeft, ev.clientY - cv.offsetTop);
document.onmousemove = function (ev) {
var ev = ev || window.event;
ctx.lineTo(ev.clientX - cv.offsetLeft, ev.clientY - cv.offsetTop);
ctx.stroke();
}
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
}
}
}
</script>
</head>
<body>
<canvas id="cv" width="400px" height="300px" style="border:1px solid #333;">
不支持canvas的浏览器
</canvas>
</body>
</html>