DHTML Object Properties DHTML Objects
Retrieves the calculated top position of the object relative to the layout or coordinate parent, as given by the offsetParent property.
HTML |
N/A |
Script |
[ iCoord = ] object.offsetTop |
iCoord |
Integer representing the top position. |
The property is read-only with no default value.
Using a combination of offset* properties, you can determine the location, width, and height of an object by using the offsetLeft, offsetTop, offsetHeight, and offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the object relative to the object’s offset parent.
For more information on how to access the dimension and location of objects on the page through the document object model, see Measuring Element Dimension and Location.
The following example demonstrates use of the offsetTop property to determine whether an object is in the user's view.
<script language="JavaScript">
function isinView ( oObject ) {
var oParent = oObject.offsetParent;
var iOffsetTop = oObject.offsetTop;
var iClientHeight = oParent.clientHeight;
if ( iOffsetHeight > iClientHeight ) {
alert ( "Scroll down for the message." );
}
}
</script>
...
<button onclick="isinView ( this )">
Click here</button>
...
<div id=oDiv
STYLE="position:absolute; top:900; left:0;">
...
</div>
This feature requires Microsoft® Internet Explorer® 4.0 or later.
Show me
offsetParent, Measuring Element Dimension and Location