offsetX Property

DHTML, HTML, & CSS

offsetX Property


Retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event.

Syntax

HTMLN/A
Scripting[ iCoord = ] event.offsetX

Possible Values

iCoordInteger that specifies the x-coordinate, in pixels.

The property is read-only with no default value.

Remarks

The coordinates match the offsetLeft and offsetTop properties of the object. Use offsetParent to find the container object that defines this coordinate system.

Example

This example uses the offsetX property to determine the mouse position relative to the container that fired the event, and displays the mouse coordinates in the status bar at the bottom of the window.

Sample Code

<SCRIPT>
function offsetCoords()
{
    var offsetInfo = ""
    offsetInfo = "The x coordinate is: " + window.event.offsetX + "\r"
    offsetInfo += "The y coordinate is: " + window.event.offsetY + "\r"
    alert(offsetInfo);
}
</SCRIPT>
</HEAD>
<BODY onmousemove="window.status = 'X=' + window.event.offsetX + 
    ' Y=' + window.event.offsetY" ondblclick="offsetCoords()">
:
<DIV onclick="offsetCoords();" . . . position:absolute; top:200;
    left:300;">
:
</DIV>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
HTML N/A
Scripting event

Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.