点击某个锚时,我希望我的页面转到顶部.
这是我试图这样做但它不起作用,它滚动速度超快.
$('a[href=#top]').click(function () {
$('body').animate({
scrollTop: 0
},
50);
});
Run Code Online (Sandbox Code Playgroud)
我想放慢速度.
有没有办法加快 的行为速度scrollTo?
我在黑暗中刺了一下speed,duration但不起作用!
window.scrollTo({
top: 1000,
behavior: "smooth"
});
Run Code Online (Sandbox Code Playgroud)
现在我正在使用这个:
$('#go-to-top').each(function(){
$(this).click(function(){
$('html').animate({ scrollTop: 0 }, 'slow'); return true;
});
});
Run Code Online (Sandbox Code Playgroud)
这在Chrome中不起作用,在Opera中我得到一个小闪烁:浏览器立即滚动到顶部,然后回到底部,然后它开始慢慢地滚动回顶部,就像它应该的那样.
有一个更好的方法吗?