【问题标题】:Animate jQuery scrolltop动画 jQuery 滚动顶部
【发布时间】:2012-08-01 18:14:27
【问题描述】:

我在 jQuery 中有一个 scrollTop 函数,但我不能为它制作动画。有可能吗?

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

【问题讨论】:

  • 您是否尝试过使用.animate().scrollTop 不接受持续时间参数。 jQuery Docs

标签: jquery jquery-ui jquery-animate scrolltop


【解决方案1】:

您可以为此使用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/

【讨论】:

  • 当我们在动画播放时尝试滚动时,这会产生什么问题吗?我正面临这样的问题,但我在 setTimeout() 中调用了这个。 scoll 似乎有问题。
【解决方案2】:
$('html, body').animate({ scrollTop: $('.docs').offset().top}, 2000);

【讨论】:

    【解决方案3】:
    $('#ID').click(function(){
    $("html, body").animate({ scrollTop: 0 }, 1000);
    return false;         });
    

    试试这段Jquery代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多