blob: aaeb7486a8522563218c971c0c61225f0f4fe67a (
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
117
118
119
|
---
title: Element.scrollWidth
slug: Web/API/Element/scrollWidth
translation_of: Web/API/Element/scrollWidth
---
<div>{{ APIRef("DOM") }}</div>
<p>La propiedad de sólo lectura <strong><code>Element.scrollWidth</code></strong> retorna bien la anchura en pixels del contenido de un elemento o bien la anchura del elemento en si, la que sea mayor de ambas. Si el elemento es más ancho que su área contenedora (por ejemplo, si existen barras de desplazamiento para desplazarse a través del contenido), <code>scrollWidth</code> es mayor que <code>clientWidth</code>.</p>
<div class="note">
<p>El valor de esta propiedad será red redondedo a un entero. Si necesita un valor fraccional, use {{ domxref("element.getBoundingClientRect()") }}.</p>
</div>
<h2 id="Syntax_and_values" name="Syntax_and_values">Sintaxis</h2>
<pre class="syntaxbox">var <var>xScrollWidth</var> = <var>element</var>.scrollWidth;</pre>
<p><var>xScrollWidth</var> es el ancho del contenido de <var>element</var> en pixels.</p>
<h2 id="Example" name="Example">Ejemplo</h2>
<pre class="brush:html"><!DOCTYPE html>
<html>
<head>
<title>Ejemplo</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');
//comprueba si un desbordamiento está ocurriendo
function isOverflowing(element) {
return (element.scrollWidth > element.offsetWidth);
}
function alertOverflow(element) {
if (isOverflowing(element)) {
alert('El contenido desborda el contenedor.');
} else {
alert('Sin desobordamiento!');
}
}
buttonOne.addEventListener('click', function() {
alertOverflow(divOne);
});
buttonTwo.addEventListener('click', function() {
alertOverflow(divTwo);
});
</script>
</html>
</pre>
<h2 id="Specification" name="Specification">Especificación</h2>
<table class="standard-table">
<tbody>
<tr>
<th>Especificación</th>
<th>Estado</th>
<th>Observaciones</th>
</tr>
<tr>
<td>{{SpecName("CSSOM View", "#dom-element-scrollwidth", "Element.scrollWidth")}}</td>
<td>{{Spec2("CSSOM View")}}</td>
<td>Definición inicial</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.Element.scrollWidth")}}</p>
<h2 id="See_also" name="See_also">Ver también</h2>
<ul>
<li>{{domxref("Element.clientWidth")}}</li>
<li>{{domxref("HTMLElement.offsetWidth")}}</li>
<li><a href="/en-US/docs/Determining_the_dimensions_of_elements">Determinando las dimensiones de elementos</a></li>
</ul>
|