Canvas offsetTop and offsetLeft
在HTML5 Canvas中,offsetTop和offsetLeft是什么?
我正在尝试获取鼠标单击事件的X和Y。我知道我可以通过以下方式实现:
1 2 3 4 | mycanvas.onclick = function (evt) { var offX = evt.layerX - mycanvas.offsetLeft; var offY = evt.layerY - mycanvas.offsetTop; } |
但是offsetLeft和offsetTop是什么?什么是LayerX和LayerY?
offsetLeft属性特定于元素,在本文档中描述为:
Returns the number of pixels that the upper left corner of the current
element is offset to the left within the offsetParent node.
特定于事件的LayerX,在本文档中描述为:
Returns the horizontal coordinate of the event relative to the current
layer.
希望有帮助!
根据MSDN的文档,layerX和layerY相对于DOM树中最接近的祖先。
我也在尝试解决此问题...