Gets the y-coordinate of the mouse cursor, relative to the target node.
Property of dom/objects/MouseEventdom/objects/MouseEvent
SyntaxNote: This property is read-only.
var yCoordinate = event.offsetY;
Return Value
Returns an object of type NumberNumber
The Y coordinate of the mouse cursor.
ExamplesThis example uses the offsetY property to determine the mouse position relative to the container that fired the event, and also displays the mouse coordinates in the console.
<!doctype html>
<html>
<head>
<style>
#div {
position:absolute;
top:200px;
left:300px;
}
</style>
<script>
function offsetCoords(e) {
var offsetInfo = ""
offsetInfo = "The x coordinate is: " + e.offsetX + "\n"
offsetInfo += "The y coordinate is: " + e.offsetY + "\r"
console.log(offsetInfo);
}
function logCoords(e) {
console.log("X = " + e.offsetX + " Y = " + e.offsetY);
}
function initialize() {
document.body.addEventListener("mousemove", logCoords, false);
document.body.addEventListener("click", offsetCoords, false);
document.getElementById("div").addEventListener("click", offsetCoords, false);
}
window.addEventListener("load", initialize, false);
</script>
</head>
<body>
<div id="div">
</div>
</body>
</html>
Notes
Offset coordinates include the padding of an element, but not its margin or border.
TODO: Check that this is correct.
The coordinates match the offsetLeft and offsetTop properties of the object. Use offsetParent to find the container object that defines this coordinate system.
Related specificationsoffsetY
Reference
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4