-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas_Zeichnen_Maus_und_Touch.html
72 lines (58 loc) · 1.97 KB
/
canvas_Zeichnen_Maus_und_Touch.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<style>
#canvas1 {
background-color: aqua;
/*Das Canvas beim zeichnen nicht scrollt*/
touch-action: none;
}
</style>
<script>
'use strict';
window.onerror = function (e) { alert('Meine Fehlermeldung!: ' + e) };
window.onload = function () {
//Gib Zeichenfläche
var c = canvas1.getContext('2d');
//Style für Striche
c.strokeStyle = "#FF0000";
c.lineWidth = 20;
//Zum einmaligen Ansetzen des Stiftes
var flag = true;
//Pointer Events Abfangen
canvas1.addEventListener('pointerup', handlerPointerup);
canvas1.addEventListener('pointerdown', handlerPointerdown);
canvas1.addEventListener('pointermove', handlerPointermove);
//Pointer Handler +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function handlerPointerup(e) {
flag = true;
}
function handlerPointerdown(e) {
c.closePath();
}
function handlerPointermove(e) {
if (e.buttons == 1) {
zeichnen(e.offsetX, e.offsetY)
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zeichnen(x, y) {
if (flag) {
//Stift Ansetzen
c.beginPath();
c.moveTo(x, y);
flag = false;
} else {
//Zeichnen
c.lineTo(x, y);
c.stroke();
}
}
}
</script>
</head>
<body>
<canvas style="margin:50px" id="canvas1" height="800" width="1700"></canvas>
</body>
</html>