0

I have a canvas:

Canvas = function(){ //v1.0
  var o = this;
  (o.penPos = {x: 0, y: 0}, 
   o.pixelSize = 10, 
   o.pen = {style: "solid", size: 1, color: "#000"}, 
   o.brush = {style: "solid", color: "#000"});
};

I am doing the following on click event:

document.onclick = function(e){
  canvas.pixel(e.x, e.y);
}

but it doesn't show the co ordinates in correct position, I don't know what is going wrong, as I am new to UI designing.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Phalguni Mukherjee
  • 623
  • 3
  • 11
  • 29

1 Answers1

0

If you are going to listen for clicks on document you want:

event.offsetX 
event.offsetY

To get the coordinates relative to the canvas element. You will also need to check that your target element is the canvas element of interest.

You may be better off listening for clicks on the canvas element itself.

dc5
  • 12,341
  • 2
  • 35
  • 47