在 HTML5 Canvas 中什么是 offsetTop 和 offsetLeft ?
我正在尝试获取鼠标单击事件的 X 和 Y。我知道我可以通过:
mycanvas.onclick = function (evt) {
var offX = evt.layerX - mycanvas.offsetLeft;
var offY = evt.layerY - mycanvas.offsetTop;
}
但什么是 offsetLeft 和 offsetTop?什么是 LayerX 和 LayerY?
最佳答案
offsetLeft 属性特定于元素,在 documentation 中有描述。作为:
Returns the number of pixels that the upper left corner of the current element is offset to the left within the offsetParent node.
特定于事件的 LayerX 并在此 documentation 中进行了描述作为:
Returns the horizontal coordinate of the event relative to the current layer.
希望对您有所帮助!
关于javascript - Canvas offsetTop 和 offsetLeft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7821962/