scrollWidth Property

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
scrollTop Property     search Property     DHTML Properties    

scrollWidth Property


Retrieves the scrolling width of the object.

Syntax

HTMLN/A
Scripting[ iWidth = ] object.scrollWidth

Possible Values

iWidthNon-negative integer that specifies the width, in pixels.

The property is read-only with no default value.

Remarks

The width is the distance between the left and right edges of the object's visible content.

For more information about how to access the dimension and location of objects on the page through the document object model, see measuring element dimension and locationInternet Link.

Example

This example uses the scrollWidth property to compare the rendered width of a DIV element with the width of the content. The width of the element, as rendered on the page, is exposed through the offsetWidth property.

When the overflow property is set to auto, the content can exceed the dimensions of an element, and scroll bars appear. You can use the scrollWidth property to retrieve the width of the content within the element.

Sample Code

<SCRIPT>
function fnCheckScroll(){
   var iScrollWidth = oDiv.scrollWidth;
   var iOffsetWidth = oDiv.offsetWidth;
   var iDifference = iScrollWidth - iOffsetWidth;
   alert("Width: " + iOffsetWidth
      + "\nContent Width: " + iScrollWidth
      + "\nDifference: " + iDifference); 
}
</SCRIPT>
:
<DIV ID=oDiv STYLE="overflow:scroll; height=200; width=250; 
   text-align:left">
:
</DIV>
<INPUT TYPE=button VALUE="Check scrollWidth" 
   onclick="fnCheckScroll()">

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
A, ADDRESS, APPLET, B, BDO, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, custom, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FORM, HEAD, Hn, HTML, I, 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, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MENU, META, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP

See Also

scrollHeight, scrollLeft, scrollTop, width


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.