blob: 9f0c3009b5fc027f892e1f34cf6d1e6470cc6720 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
---
title: Element.scrollWidth
slug: Web/API/Element/scrollWidth
translation_of: Web/API/Element/scrollWidth
---
<div>{{ APIRef("DOM") }}</div>
<p>A propriedade de somente leitura <strong><code>Element.scrollWidth</code></strong> retorna a largura em pixels do conteúdo de um elemento ou a largura do elemento em si, o que for maior. Se o elemento for mais amplo do que a área de conteúdo (por exemplo, se houver barras de rolagem para percorrer o conteúdo), o <code>scrollWidth</code> é maior do que o <code>clientWidth</code>.</p>
<div class="note">
<p>Esta propriedade irá arredondar o valor para um número inteiro. Se você precisar de um valor fracionário, use {{ domxref("element.getBoundingClientRect()") }}.</p>
</div>
<h2 id="Syntax_and_values" name="Syntax_and_values">Syntaxe</h2>
<pre class="syntaxbox">var <var>xScrollWidth</var> = <var>element</var>.scrollWidth;</pre>
<p><var>xScrollWidth</var> é a largura do conteúdo do <var>elemento</var> em pixels.</p>
<h2 id="Example" name="Example">Examplo</h2>
<pre class="brush:html"><!DOCTYPE html>
<html>
<head>
<title>Example</title>
<style>
div {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
#aDiv {
width: 100px;
}
button {
margin-bottom: 2em;
}
</style>
</head>
<body>
<div id="aDiv">
FooBar-FooBar-FooBar-FooBar
</div>
<button id="aButton">
Check for overflow
</button>
<div id="anotherDiv">
FooBar-FooBar-FooBar-FooBar
</div>
<button id="anotherButton">
Check for overflow
</button>
</body>
<script>
var buttonOne = document.getElementById('aButton'),
buttonTwo = document.getElementById('anotherButton'),
divOne = document.getElementById('aDiv'),
divTwo = document.getElementById('anotherDiv');
//check to determine if an overflow is happening
function isOverflowing(element) {
return (element.scrollWidth > element.offsetWidth);
}
function alertOverflow(element) {
if (isOverflowing(element)) {
alert('Contents are overflowing the container.');
} else {
alert('No overflows!');
}
}
buttonOne.addEventListener('click', function() {
alertOverflow(divOne);
});
buttonTwo.addEventListener('click', function() {
alertOverflow(divTwo);
});
</script>
</html>
</pre>
<h2 id="Specification" name="Specification">Especificação</h2>
<table class="standard-table">
<tbody>
<tr>
<th>Especificação</th>
<th>Status</th>
<th>Comentário</th>
</tr>
<tr>
<td>{{SpecName("CSSOM View", "#dom-element-scrollwidth", "Element.scrollWidth")}}</td>
<td>{{Spec2("CSSOM View")}}</td>
<td>Definição inicial</td>
</tr>
</tbody>
</table>
<h2 id="References" name="References">Referências</h2>
<p>{{Compat("api.Element.scrollWidth")}}</p>
<h2 id="See_also" name="See_also">Veja também</h2>
<ul>
<li>{{domxref("Element.clientWidth")}}</li>
<li>{{domxref("HTMLElement.offsetWidth")}}</li>
<li><a href="/en-US/docs/Determining_the_dimensions_of_elements">Determinando as dimensões dos elementos</a></li>
</ul>
|