[英]Slow down scroll to top event by jQuery animate
I'd like my page to go to the top when certain anchor is clicked. 点击某个锚时,我希望我的页面转到顶部。
Here is how I tried to do it but it's not working, it's scrolling super fast. 这是我试图这样做但它不起作用,它滚动速度超快。
$('a[href=#top]').click(function () {
$('body').animate({
scrollTop: 0
},
50);
});
I want to slow it down. 我想放慢速度。
$('a[href=#top]').click(function(){
$('html, body').animate({scrollTop:0}, 'slow');
});
Perhaps? 也许?
you can set the time for scroll top 您可以设置滚动顶部的时间
$('a[href=#top]').click(function(){
$('body').animate({
scrollTop: 0},4000);});
$('a[href=\\#top]').click(function(){
$('body').animate(
{
scrollTop: 0
},
2000
);
});
The # should be escaped \\\\#. #应该被转义\\#。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.