This code:
jQuery('body').animate({scrollTop: target.offset().top}, 300);
Works in firefox, but not chrome.
This code:
jQuery('html').animate({scrollTop: target.offset().top}, 300);
Works in chrome, but not firefox.
I haven't tested yet in IE.
What is the correct way to do this, cross-browser? If it's not clear from the above snippets, I target is a div on the page, and I want to scroll down slowly to it slowly, so they do exactly what I want... just not cross-browser.
Specify both html and body:
$("html,body").animate({scrollTop: target.offset().top}, 300);
来源:https://stackoverflow.com/questions/15664799/how-to-scroll-to-element-cross-browser-using-jquery-animate