动画jQuery scrolltop
我在jQuery中有一个scrollTop函数,但我无法为其设置动画。 可能吗?
$(".loadmore").click(function() { $(this).toggleClass("up-arrow", 1000); $(window).scrollTop($('.docs').offset().top, 2000); });
您可以使用animate()
来实现此目的。
应用于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.
演示可以在这里找到: http : //jsfiddle.net/codebombs/GjXzD/
$('html, body').animate({ scrollTop: $('.docs').offset().top}, 2000);
$('#ID').click(function(){ $("html, body").animate({ scrollTop: 0 }, 1000); return false; });
试试这个Jquery代码