Windows Dev Center

all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize

offsetTop property

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.

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.


<html>

<head>
<script type="text/javascript">
function isinView(oObject)
{
    var oParent = oObject.offsetParent; 
    var iOffsetTop = oObject.offsetTop;
    var iClientHeight = oParent.clientHeight;
    if (iOffsetTop > iClientHeight) {
        console.log("Special Text not in view. Expand Window to put Text in View.");
    }
    else{
         console.log("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
address
area
b
bdo
blockQuote
body
br
button
caption
cite
code
col
colGroup
custom
dd
del
dfn
div
dl
dt
em
embed
fieldSet
form
frame
hn
hr
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
kbd
label
legend
li
map
menu
object
ol
option
p
pre
q
rt
ruby
s
samp
select
small
span
strong
sub
sup
table
tBody
td
textArea
TextRange
tFoot
th
tHead
tr
u
ul
var
Reference
boundingHeight
boundingLeft
boundingTop
boundingWidth

 

 

Show:
© 2015 Microsoft