这段代码:
jQuery('body').animate({scrollTop: target.offset().top}, 300);
适用于 Firefox,但不适用于 Chrome。
这段代码:
jQuery('html').animate({scrollTop: target.offset().top}, 300);
适用于 chrome,但不适用于 firefox。
我还没有在 IE 中测试过。
跨浏览器的正确方法是什么?如果从上面的代码片段中看不清楚,我的目标是页面上的一个 div,我想慢慢向下滚动到它,所以它们完全符合我的要求...只是不跨浏览器。
最佳答案
同时指定 html
和 body
:
$("html,body").animate({scrollTop: target.offset().top}, 300);
关于javascript - 如何滚动到元素跨浏览器使用 jquery animate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15664799/