- commit
- 3f659fa9d54587cbb79ea8bcd1757ea99ffb3ce3
- parent
- 4c8743574b19679f2b06b5da74e25ecb397ac528
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-12-17 18:07
fix canvas for touch devices
Diffstat
M | canvas.js | 16 | +++++++++++++--- |
1 files changed, 13 insertions, 3 deletions
diff --git a/canvas.js b/canvas.js
@@ -3,14 +3,24 @@ canvas.width = 16; 3 3 canvas.height = 16; 4 4 var ctx = canvas.getContext('2d'); 5 56 -1 canvas.addEventListener('mousemove', function(event) {7 -1 if (!(event.buttons & 1)) return;8 -1-1 6 var onmove = function(event) { 9 7 var x = Math.floor((event.clientX - canvas.offsetLeft) / canvas.clientWidth * 16); 10 8 var y = Math.floor((event.clientY - canvas.offsetTop) / canvas.clientHeight * 16); 11 9 12 10 ctx.fillStyle = 'black'; 13 11 ctx.fillRect(x, y, 1, 1); -1 12 }; -1 13 -1 14 canvas.addEventListener('pointermove', function(event) { -1 15 if (event.pointerType !== 'mouse') { -1 16 onmove(event); -1 17 } -1 18 }); -1 19 -1 20 canvas.addEventListener('mousemove', function(event) { -1 21 if (event.buttons & 1) { -1 22 onmove(event); -1 23 } 14 24 }); 15 25 16 26 export var clear = function() {