-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path20.html
More file actions
41 lines (36 loc) · 1.26 KB
/
Copy path20.html
File metadata and controls
41 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Drawing App</title>
</head>
<body>
<h1>Simple Drawing App</h1>
<canvas id="canvas" width="500" height="500" style="border:1px solid #000000;"></canvas>
<script>
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
let isDrawing = false;
function startDrawing(event) {
isDrawing = true;
context.beginPath();
context.moveTo(event.clientX - canvas.offsetLeft, event.clientY - canvas.offsetTop);
}
function continueDrawing(event) {
if (isDrawing) {
context.lineTo(event.clientX - canvas.offsetLeft, event.clientY - canvas.offsetTop);
context.stroke();
}
}
function stopDrawing() {
isDrawing = false;
context.closePath();
}
canvas.addEventListener('mousedown', startDrawing);
canvas.addEventListener('mousemove', continueDrawing);
canvas.addEventListener('mouseup', stopDrawing);
canvas.addEventListener('mouseleave', stopDrawing);
</script>
</body>
</html>