动画jQuery滚动顶部 [英] Animate jQuery scrolltop

查看:72
本文介绍了动画jQuery滚动顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jQuery中有一个scrollTop函数,但无法对其进行动画处理.有可能吗?

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);
});

推荐答案

您可以为此使用animate().

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

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.

演示可在此处找到: http://jsfiddle.net/codebombs/GjXzD/

这篇关于动画jQuery滚动顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆