动画 jQuery 滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11800090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:58:08  来源:igfitidea点击:

Animate jQuery scrolltop

jqueryjquery-uijquery-animatescrolltop

提问by George

I have a scrollTop function in jQuery but I can't animate it. Is it possible?

我在 jQuery 中有一个 scrollTop 函数,但我无法为它设置动画。是否可以?

$(".loadmore").click(function() {
  $(this).toggleClass("up-arrow", 1000);
  $(window).scrollTop($('.docs').offset().top, 2000);
});

回答by Sasidhar Vanga

You can use animate()for this.

您可以animate()为此使用。

Example code applied on a divis as follows :

应用于 a 的示例代码div如下:

//Scroll to bottom
$('div').animate({scrollTop: $('div').get(0).scrollHeight}, 3000);

//$('div').get(0).scrollHeight - will give the full height of div.
//scrollTop - will be used to animate from the current position to page end.
//3000 - will be the duration.

Demo can be found here : http://jsfiddle.net/codebombs/GjXzD/

演示可以在这里找到:http: //jsfiddle.net/codebombs/GjXzD/

回答by Ifeanyi Chukwu

$('html, body').animate({ scrollTop: $('.docs').offset().top}, 2000);

回答by loyola

$('#ID').click(function(){
$("html, body").animate({ scrollTop: 0 }, 1000);
return false;         });

Try this code of Jquery

试试这个 Jquery 代码