Skip to content

Commit 9c7c7dd

Browse files
authored
Update script.js
#970
1 parent 37aad05 commit 9c7c7dd

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

Projects/WhiteBoard/script.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Get canvas element and set its dimensions to the size of the screen
21
var canvas = document.getElementById("canvas");
32
const colorPicker = document.getElementById("color-picker");
43
const saveButton = document.getElementById("save-button");
@@ -110,16 +109,12 @@ canvas.addEventListener('touchend', function () {
110109
ctx.stroke();
111110
}
112111
});
113-
canvas.addEventListener('touchmove', function (e) {
114-
if (drawing) {
115-
// Draw a line from the last coordinates to the current ones
112+
canvas.addEventListener('touchend', function (e) {
113+
drawing = false;
114+
if (currentTool == "line") {
116115
ctx.beginPath();
117-
ctx.moveTo(lastX, lastY);
118-
ctx.lineTo(e.touches[0].pageX, e.touches[0].pageY);
116+
ctx.moveTo(lineStart.x, lineStart.y);
117+
ctx.lineTo(e.touches[0].pageX - canvas.offsetLeft, e.touches[0].pageY - canvas.offsetTop);
119118
ctx.stroke();
120-
121-
// Update last coordinates
122-
lastX = e.touches[0].pageX;
123-
lastY = e.touches[0].pageY;
124119
}
125120
});

0 commit comments

Comments
 (0)