blob: ec2c61ab41735b31dd19e5faefdb00cbbe9e17d7 (
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
|
---
title: Window.scroll()
slug: Web/API/Window/scroll
tags:
- API
- CSSOM View
- Referencia
- metodo
translation_of: Web/API/Window/scroll
---
<div>{{APIRef}}</div>
<p>El método <code><strong>Window.scroll()</strong></code> desplaza la ventana a un lugar particular en el documento.</p>
<h2 id="Sintaxis">Sintaxis</h2>
<pre class="syntaxbox">window.scroll(<em>x-coord</em>, <em>y-coord</em>)
window.scroll(<em>options</em>)
</pre>
<h3 id="Parámetros">Parámetros</h3>
<ul>
<li><code>x-coord</code> es la coordenada sobre el eje horizontal del documento del pixel que querés que se muestre en la parte superior izquierda.</li>
<li><code>y-coord</code> es la coordenada sobre el eje vertical del documento del pixel que querés que se muestre en la parte superior izquierda.</li>
</ul>
<p>- o -</p>
<ul>
<li><code>options</code> es un diccionario {{domxref("ScrollToOptions")}}.</li>
</ul>
<h2 id="Ejemplo">Ejemplo</h2>
<pre class="brush:html;htmlScript:true;"><!-- poner el pixel 100º verticalmente en el tope superior de la ventana -->
<button onClick="scroll(0, 100);">Clic para desplazarse hacia abajo 100 pixeles</button>
</pre>
<p>Utilizando <code>options</code>:</p>
<pre class="brush: js">window.scroll({
top: 100,
left: 100,
behavior: 'smooth'
});</pre>
<h2 id="Notas">Notas</h2>
<p>{{domxref("Window.scrollTo()")}} es efectivamente idéntico a este método. Para desplazamiento relativo, mira {{domxref("Window.scrollBy()")}}, {{domxref("Window.scrollByLines()")}} y {{domxref("Window.scrollByPages()")}}.</p>
<p>Para desplazarse sobre elementos, mira {{domxref("Element.scrollTop")}} y {{domxref("Element.scrollLeft")}}.</p>
<h2 id="Especificación">Especificación</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Especificación</th>
<th scope="col">Estado</th>
<th scope="col">Comentario</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ SpecName('CSSOM View', '#dom-window-scroll', 'window.scroll()') }}</td>
<td>{{ Spec2('CSSOM View') }}</td>
<td>Definición inicial.</td>
</tr>
</tbody>
</table>
<h2 id="Compatibilidad_en_navegadores">Compatibilidad en navegadores</h2>
<p>{{Compat("api.Window.scroll")}}</p>
<h2 id="Ver_también">Ver también</h2>
<ul>
<li>{{domxref("Window.scrollByLines()")}}</li>
<li>{{domxref("Window.scrollByPages()")}}</li>
<li>{{domxref("Element.scrollIntoView()")}}</li>
</ul>
|