Get bounding client rectangle without borders
问题 I made a function that transforms mouse coordinates to canvas pixel coordinates: /* Returns pixel coordinates according to the pixel that's under the mouse cursor**/ HTMLCanvasElement.prototype.relativeCoords = function(event) { var x,y; //This is the current screen rectangle of canvas var rect = this.getBoundingClientRect(); //Recalculate mouse offsets to relative offsets x = event.clientX - rect.left; y = event.clientY - rect.top; //Also recalculate offsets of canvas is stretched var width