www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Properties
 offsetTop Property
offsetTop Property

Retrieves the calculated top position of the object relative to the layout or coordinate parent, as specified by the offsetParent property.

Syntax

HTMLN/A
Scripting[ iCoord = ] object.offsetTop

Possible Values

iCoordInteger that receives the top position, in pixels.

The property is read-only. The property has no default value.

Remarks

You can determine the location, width, and height of an object by using a combination of 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 about how to access the dimension and location of objects on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location.

Example

This example uses the offsetTop property to determine whether an object is in the user's view.

<html>

<head>
<script type="text/javascript">
function isinView(oObject)
{
    var oParent = oObject.offsetParent; 
    var iOffsetTop = oObject.offsetTop;
    var iClientHeight = oParent.clientHeight;
    if (iOffsetTop > iClientHeight) {
        alert("Special Text not in view. Expand Window to put Text in View.");
    }
    else{
         alert("Special Text in View!");
    }
}
</script>
</head>

<body   scroll="NO">

<div style="position: absolute; left: 20px">
    Click anywhere in window to see if special text is in view.</div>
<div id="oID_1" style="position: absolute; 
    left: 50px; 
    top: 300px; 
    width: 280px; 
    color: silver; 
    font-size: large; 
    font-weight: bold; 
    background-color: aqua; 
    font-family: Arial">
    Here&#39;s some special text </div>

</body>

</html>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

There is no public standard that applies to this property.

Applies To

A, ABBR, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, CUSTOM, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, hn, HR, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TextRange, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

See Also

boundingHeight, boundingLeft, boundingTop, boundingWidth
Tags What's this?: Add a tag
Community Content
 
Add Community Content
Measuring the right way at the right time      Kai Habel   |   Edit   |  

Beware of using this property too early, because the properties offsetLeft and offsetTop may return zero length if questioned before the containing document has finished rendering.

Wait for the page to render completely before calling them - especially when using them from inside a viewLink object.

In case of determining the position of a viewLink object embedded into e.g. a table object use the ondocumentready event.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG