I found this is exactly what I want: jQuery .scrollTop(); + animation
var body = $("html, body");
body.stop().animate({scrollTop:0}, 500, 'swing', function() {
alert("Finished animating");
});
But the problem as a comment mentioned in the question is that the trigger function would fire twice.
I realize that it's because $("html, body")
get two elements binding this event.
However, I noticed that I can't just simply remove one because in Safari it's body
that works while in Chrome it's html
that works.
And I don't know what would happen on other devices that I could access.
So, is there any perfect solution for this that I don't need to fire twice the function?