Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  189] [ 4]  / answers: 1 / hits: 30012  / 13 Years ago, wed, october 19, 2011, 12:00:00

In HTML5 Canvas what is offsetTop and offsetLeft ?



I'm trying to get the X and Y of a a mouse click event. I know I can get that through:



mycanvas.onclick = function (evt) {
var offX = evt.layerX - mycanvas.offsetLeft;
var offY = evt.layerY - mycanvas.offsetTop;
}


but what is offsetLeft and offsetTop? and what is LayerX and LayerY ?


More From » html

 Answers
4

The offsetLeft properties are specific to elements and is described in this documentation as:




Returns the number of pixels that the upper left corner of the current
element is offset to the left within the offsetParent node.




LayerX specific to events and is described in this documentation as:




Returns the horizontal coordinate of the event relative to the current
layer.




Hope that helps!


[#89532] Tuesday, October 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
davism

Total Points: 339
Total Questions: 100
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
;