-
Notifications
You must be signed in to change notification settings - Fork 266
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
Document how to use scrollTop() properly #417
Comments
I just reopened the Core ticket, see there for details: http://bugs.jquery.com/ticket/14515#comment:8 |
I left some comments in #425 about the message here, I think we need to re-word it a bit and also add a similar note to |
@jzaefferer I left a comment on the Core ticket for you. |
Since Core won't try to normalize this, all we can do is document the canonical solution. Afaik this snippet works consistently and produces a single callback: $( "html, body" ).animate({
// scroll to end of page
scrollTop: $(document).height()
}, 800).promise().then(function() {
console.log("runs once!")
}); @leobalter would you update your branch and create a new PR? Thanks. |
That snippet has other side effects... Namely: $( "html, body" ).animate({
// scroll to end of page
scrollTop: $(document).height()
}, 800).promise().then(function() {
console.log("runs once!")
}).animate({
scrollTop: 0
}, 800); // but only after this animation ALSO finishes
$("body").animate({opacity: 0}, 500); // oh this one too The promise on a jQuery object only gets called when its default animation queue empties, not as an inline callback to animation completion. |
As gnarf said, you probably want something akin to this: $.Deferred(function( defer ) {
$( "html, body" ).animate({
// scroll to end of page
scrollTop: $(document).height()
}, 800, defer.resolve );
}).done(function() {
console.log( "runs once!" )
}); |
IMHO, some of these examples are looking way complex to be presented as examples. I think we can use the suggestions made by @gnarf to mention scrollLeft and we can also add another example using It might be worth to mention that jQuery Core don't try to force a normalization on this and explain why it's needed to handle |
We can start with an example that doesn't have the callback, to keep things simple at first. Use that to talk about the underlying issue and lack of normalization. Then talk about the issue with animation callbacks and how to deal with that, along with another example. |
Can this be an article on learn perhaps, with a link from the api docs? It's starting to sound pretty big. |
👍 to linking to a learn article. |
@leobalter Still interested in taking this? Or did you already do? |
I failed doing this. I may try it again but it shouldn't hold anyone else to fix it.
|
@arthurvr interested in taking this over? Or finding someone to write the docs? Sad to see this still open more than a year later... |
That's true for basically ever ticket open here :( One day I'll get to it for sure, but time just limits me. |
@jzaefferer Although I do definitely agree that many things in this repo are taking way too long. There are still APIs from back in 2012 undocumented, just because we lack the time and the resources. |
@arthurvr the important thing is that we are making progress, thanks to you! This issue in particular seemed to get lots of people suggesting changes without a clear consensus on what to do. I think that's why it sat around so long, it is tedious to sort through these kinds of tickets and there is always concern you'll upset someone by ignoring their concerns. So go for the low-hanging fruit if it's easier. |
Here's a good explanation of the underlying mess, along with a future-proof solution called If I read that correctly, we should document how to animate |
Via discussion in #14515.
This should be added to scrollTop():
The text was updated successfully, but these errors were encountered: