Scroll body and check if it worked:
function getScrollableRoot() {
var body = document.body;
var prev = body.scrollTop;
body.scrollTop++;
if (body.scrollTop === prev) {
return document.documentElement;
} else {
body.scrollTop--;
return body;
}
}
$(getScrollableRoot()).animate({ scrollTop: 0 }, "slow");
This is more efficient than $("html, body").animate
because only one animation used, not two. Thus, only one callback fires, not two.