Contents Index Topic Contents | ||
Previous Topic: offsetHeight Next Topic: offsetParent |
offsetLeft
Description
Returns the calculated left position, in pixels, based on the window.
Syntax
object.offsetLeft
Remarks
Using a combination of offset* properties, you can determine the location, width, and height of an element by using the offsetLeft, offsetTop, offsetHeight, and offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the element relative to the element's offset parent. For example, the following document is a simple clock that adjusts the size of its readout to fit the current width and height of the document body.
<HTML> <HEAD><TITLE>A Simple Clock</TITLE> <SCRIPT LANGUAGE="JScript"> function startClock() { window.setInterval("Clock_Tick()", 1000); Clock_Tick(); } var ratio = 4; function Clock_Tick() { var s = Date(); var t = s.substring(11,19); var doc_height = document.body.offsetHeight; var doc_width = document.body.offsetWidth; if ((doc_height*ratio)>doc_width) doc_height = doc_width / ratio; document.all.MyTime.innerText = t; document.all.MyTime.style.fontSize = doc_height; } </SCRIPT> <BODY onload="startClock()"> <P ID="MyTime"> </P> </BODY> </HTML>This property has read-only permission.
For more information on how to access the dimension and location of elements on the page through the document object model, see Measuring Element Dimension and Location.
Applies To
A, ACRONYM, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, H1, H2, H3, H4, H5, H6, HR, I, IFRAME, IMG, INPUT, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TextRange, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP
Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.