Export (0) Print
Expand All
all
alt
ch
dir
id
min
rel
top
url
URL
urn
Expand Minimize

scrollWidth property

Retrieves the scrolling width of the object.

Syntax

JavaScript

p = object.scrollWidth

 

Property values

Type: Integer

Pointer to a nonnegative long integer that specifies the width, in pixels.

Remarks

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

This property is read-only on HTML documents, and read-write on fixed regions.

For more information about how to access the dimension and location of objects on the page through the Document Object Model (DOM), see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.

Examples

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.

This example uses the scrollWidth property to compare the viewable width of the content to the actual width of a div element. The width of the element is exposed through the offsetWidth property.

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


<script type="text/javascript">
function fnCheckScroll() {
   var iScrollWidth = oDiv.scrollWidth;
   var iOffsetWidth = oDiv.offsetWidth;
   var iDifference = iScrollWidth - iOffsetWidth;
   alert("Width: " + iOffsetWidth
      + "\nscrollWidth: " + iScrollWidth
      + "\nDifference: " + iDifference); 
}
</script>
...
<div id="oDiv" style="overflow: scroll; height= 50px; width= 400px; text-align: left" nowrap>
	... 
</div>
<button onclick="fnCheckScroll()">Check scrollWidth</button>

See also

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=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
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
Reference
scrollHeight
scrollLeft
scrollTop

 

 

Show:
© 2014 Microsoft