blob: 6d556c1eae1555cf44108f2fa874f545a0a2fb0d (
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
|
---
title: Window.scrollY
slug: Web/API/Window/scrollY
translation_of: Web/API/Window/scrollY
---
<div>{{APIRef}}</div>
<p>La propriété <code><strong>scrollY</strong></code> de l'objet {{domxref("Window")}} est une propriété en lecture seule. Elle retourne le nombre de pixels la page actuellement défilés verticalement. Dans les navigateurs modernes, cette valeur est précise au sous-pixel près. Ainsi, la valeur retournée n'est pas forcement un entier.</p>
<h2 id="Syntax">Syntaxe</h2>
<pre class="syntaxbox">var y = window.scrollY;</pre>
<ul>
<li><code>y</code> est le nombre de pixels verticaux défilés.</li>
</ul>
<h2 id="Example">Exemple</h2>
<pre class="brush:js">// make sure and go down to the second page
if (window.scrollY) {
window.scroll(0, 0); // reset the scroll position to the top left of the document.
}
window.scrollByPages(1);</pre>
<h2 id="Notes">Notes</h2>
<p>Utilisez cette propriété pour être sûre que le document n'as pas été défilé verticalement si vous utilisez les fonctions de défilement tels que {{domxref("window.scrollBy")}}, {{domxref("window.scrollByLines")}}, ou {{domxref("window.scrollByPages")}}.</p>
<p>La propriété <code>pageYOffset</code> est un alias de la propriété <code>scrollY</code>:</p>
<pre>window.pageYOffset == window.scrollY; // toujours vrai</pre>
<p>Pour une compatibilité multi-navigateur, utilisez <code>window.pageYOffset</code> à la place de <code>window.scrollY</code>. <strong>En outre</strong>, les anciennes versions d'Internet Explorer (< 9) ne supportent pas non plus la propriété et doit-être utilisé à l'aide d'autres propriétés qui ne sont pas standards. Un exemple entièrement compatible :</p>
<pre class="brush:js">var supportPageOffset = window.pageXOffset !== undefined;
var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat");
var x = supportPageOffset ? window.pageXOffset : isCSS1Compat ? document.documentElement.scrollLeft : document.body.scrollLeft;
var y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
</pre>
<h2 id="Specification">Spécifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Spécification</th>
<th scope="col">Status</th>
<th scope="col">Commentaire(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ SpecName('CSSOM View', '#dom-window-scrolly', 'window.scrollY') }}</td>
<td>{{ Spec2('CSSOM View') }}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Compatibilité des navigateurs</h2>
<p>{{Compat("api.Window.scrollY")}}</p>
<h2 id="See_also">Voir aussi</h2>
<ul>
<li>{{domxref("window.scrollX")}}</li>
</ul>
|