This Meteor client code tries to use the mousemove
to draw on canvas using fillRect
, but the location where the mouse moves is different than where the drawing takes place.
'mousemove canvas.signature': function(event) {
let canvas = event.target;
let ctx = canvas.getContext('2d');
ctx.fillStyle = "#000";
ctx.fillRect(event.clientX, event.clientY, 1, 1);
}
canvas.signature {
background-color: yellow;
width: 10em;
height: 10em;
}
This image of the line drawn happened when I moved the mouse horizontally on the top part of the yellow box, the whole width, not only it did not draw to scale but its location of too fare down.
What is the problem and how to fix it? Thanks