EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

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.

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.


<script type="text/javascript">
function fnCheckScroll() {
   var iScrollWidth = oDiv.scrollWidth;
   var iOffsetWidth = oDiv.offsetWidth;
   var iDifference = iScrollWidth - iOffsetWidth;
   console.log("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
b
bdo
blockQuote
body
button
caption
cite
code
col
colGroup
custom
dd
dfn
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
kbd
label
legend
li
menu
meta
object
ol
option
p
pre
s
samp
script
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
u
ul
var
Reference
scrollHeight
scrollLeft
scrollTop

 

 

Afficher:
© 2014 Microsoft