简体   繁体   中英

How to scroll to element cross browser using jquery animate

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.

同时指定htmlbody

$("html,body").animate({scrollTop: target.offset().top}, 300);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM