9 out of 20 rated this helpful - Rate this topic

offsetTop property

[This documentation is preliminary and is subject to change.]

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

Syntax

JavaScript

p = object.offsetTop

Property values

Type: Integer

the top position, in pixels.

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.

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 with CSSOM in Internet Explorer 9.

Examples

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

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/offsetTop.htm


<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 onload="window.resizeTo(430,250)" onclick="isinView(oID_1)" 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>

See also

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
Reference
boundingHeight
boundingLeft
boundingTop
boundingWidth

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Measuring the right way at the right time

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.