Newer
Older
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<textarea style="width: 100%; height: 500px" id="textfield"></textarea>
<script src="js/app.js"></script>
<svg id="whiteboard" width="100%" height="100%"></svg>
<script>
var whiteboard = document.getElementById("whiteboard")
var painting = false
var path
whiteboard.onmousedown = function(e) {
painting = true
var mouse = {
x: e.offsetX,
y: e.offsetY
}
path = document.createElementNS("http://www.w3.org/2000/svg", "path")
path.setAttribute("d", "M" + mouse.x + " " + mouse.y)
path.setAttribute("stroke", "blue")
path.setAttribute("stroke-width", 3)
path.setAttribute("fill", "none")
path.setAttribute("pointer-events", "none")
whiteboard.appendChild(path)
}
whiteboard.onmouseup = function(e) {
painting = false
}
whiteboard.onmousemove = function(e) {
var mouse = {
x: e.offsetX,
y: e.offsetY
}
if (painting) {
path.setAttribute(
"d",
path.getAttribute("d") + " L" + mouse.x + " " + mouse.y
)
}
}
</script>
</body>
</html>