Skip to content

.scrollTop(): document proper use of scrollTop on document body #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions entries/scrollTop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ $( "p:last" ).text( "scrollTop:" + p.scrollTop() );
<desc>Set the current vertical position of the scroll bar for each of the set of matched elements.</desc>
<longdesc>
<p>The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. Setting the <code>scrollTop</code> positions the vertical scroll of each matched element.</p>
<p>Note that scrollTop can be used to read, but not write, the document scroll position. To scroll the document, animated or not, you have to call <code>scrollTop()</code> only on the body element:</p>
<pre><code>
// Without animation
$( document.body ).scrollTop( 500 );

// With animation
$( document.body ).animate({
scrollTop: 500
});
</code></pre>
<p>Any examples elsewhere that suggest <code>$( "html, body" ).animate({ scrollTop: ... });</code> are wrong, since this will cause the animation callback to get triggered twice, regarding the selector target for both <code>html</code> and <code>body</code> elements.</p>
</longdesc>
<example>
<desc>Set the scrollTop of a div.</desc>
Expand Down