简体   繁体   English

如何使滚动目标平滑

[英]How to make scrolling to target smooth

I have set up an comment button that is link to comment section of the page, it's like this Comments 我已经设置了一个评论按钮,该按钮链接到页面的评论部分,就像这个评论

Demo on this page http://stramaxon.blogspot.com/2012/04/how-to-remove-shadows-from-pictures-in.html#disqus_thread 本页演示http://stramaxon.blogspot.com/2012/04/how-to-remove-shadows-from-pictures-in.html#disqus_thread

When you click it, you will be taken to the comments section, now i want the scrolling to be smooth, i know it is possible but can't find the key to achieve it. 当你点击它,你将被带到评论部分,现在我想滚动顺利,我知道它是可能的,但无法找到实现它的关键。 I am sure intelligent web designers in Stackoverflow will help me out. 我相信Stackoverflow中的智能网页设计师会帮助我。

I want it to be like this, check this page http://www.labnol.org/internet/bing-background-for-google-homepage/21303/ 我希望它是这样的,请查看此页面http://www.labnol.org/internet/bing-background-for-google-homepage/21303/

Scroll down and you will see a back to top button, it's so smooth i love it and want something like that. 向下滚动,你会看到一个回到顶部的按钮,它是如此顺利,我喜欢它,并希望这样的东西。

$("#topBtn").click(scrollToTop);

function scrollToTop()
{
    $('html, body').animate({scrollTop:0}, 1000);
}

should work 应该管用

EDIT: that's for a non href, when you wanna use it on a href you should to it like this 编辑:这是一个非href,当你想在一个href使用它时,你应该像这样

function scrollToTop()
{
    $('html, body').animate({scrollTop:0}, 1000);
    return false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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