Window.scroll()

  • Revision slug: DOM/window.scroll
  • Revision title: window.scroll
  • Revision id: 321103
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

Summary

Scrolls the window to a particular place in the document.

Syntax

window.scroll(x-coord, y-coord) 

Parameters

  • x-coord is the pixel along the horizontal axis of the document that you want displayed in the upper left.
  • y-coord is the pixel along the vertical axis of the document that you want displayed in the upper left.

Example

<!-- put the 100th vertical pixel at the top of the window -->

<button onClick="scroll(0, 100);">click to scroll down 100 pixels</button>

Notes

window.scrollTo is effectively the same as this method. For scrolling a particular distance repeatedly, use the window.scrollBy. Also see window.scrollByLines, window.scrollByPages.

Specification

{{dom0}}

Revision Source

<div>{{DomRef}}</div>

<h2 id="Summary" name="Summary">Summary</h2>
<p>Scrolls the window to a particular place in the document.</p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="syntaxbox">
window.scroll(<i>x-coord</i>, <i>y-coord</i>) 
</pre>

<h3 id="Parameters" name="Parameters">Parameters</h3>
<ul>
  <li><code>x-coord</code> is the pixel along the horizontal axis of the document that you want displayed in the upper left.</li>
  <li><code>y-coord</code> is the pixel along the vertical axis of the document that you want displayed in the upper left.</li>
</ul>

<h2 id="Example" name="Example">Example</h2>

<pre class="brush:html;htmlScript:true;">
&lt!-- put the 100th vertical pixel at the top of the window --&gt;

&lt;button onClick="scroll(0, 100);"&gt;click to scroll down 100 pixels&lt;/button&gt;
</pre>

<h2 id="Notes" name="Notes">Notes</h2>
<p><a href="/en-US/docs/DOM/window.scrollTo">window.scrollTo</a> is effectively the same as this method. For scrolling a particular distance repeatedly, use the <a href="/en-US/docs/Window.scrollBy">window.scrollBy</a>. Also see <a href="/en-US/docs/Window.scrollByLines">window.scrollByLines</a>, <a href="/en-US/docs/Window.scrollByPages">window.scrollByPages</a>.</p>

<h2 id="Specification" name="Specification">Specification</h2>
<p>{{dom0}}</p>
Revert to this revision