jquery / jquery/api.jquery.com
Document how to use scrollTop() properly
Open
Nobody has claimed this yet.
help wanted
- Dominant language
- HTML
- Stars
- 325
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
Via discussion in #14515.
This should be added to scrollTop():
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 `scrollTop()` on the body element:
<pre><code>
// Without animation
$( document.body ).scrollTop( 500 );
// With animation
$( document.body ).animate({
scrollTop: 500
});
</code></pre>
Any examples elsewhere that suggest $( "html, body" ).animate({ scrollTop: ... }); are wrong, since this will cause the animation callback to get triggered twice.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Update entries/scrollTop.xml with the documented distinction between reading and writing the document scroll position, including the provided examples. Then review other examples that suggest using $("html, body").animate({ scrollTop: ... }); and correct them if needed. Done means the scrollTop() documentation reflects the requested guidance and no conflicting examples remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jquery
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100