Animate jQuery scrolltop

我只是一个虾纸丫 提交于 2019-12-01 04:25:51

问题


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

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

回答1:


You can use animate() for this.

Example code applied on a div is as follows :

//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/




回答2:


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



回答3:


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

Try this code of Jquery



来源:https://stackoverflow.com/questions/11800090/animate-jquery-scrolltop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!