我在我的网站上编写了一个平滑滚动的脚本,但它似乎不起作用,但其他声称它有效。(使用最新的chrome版本,没有尝试不同的浏览器)。任何建议可能是什么情况?我已经在下面的 html 页面中链接了脚本。
HTML:
<a id="top"></a>
**page content here**
<a href="#top">Go to top</a>
脚本:
$(document).ready(function() {
$('a[href^="#"').click(function() {
var target = $(this.hash);
if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
if (target.length == 0) target = $('html');
$('html, body').animate({ scrollTop: target.offset().top }, 500);
return false;
});
});