0

我需要从上到下滚动包含内容的页面,并且导航具有“显示顶部”锚点。当我单击“显示顶部”锚点时,页面(之前未显示)将从顶部滚动到包含内容的主屏幕区域。

.topPage{
    width:1280px; 
    color:#000; 
    float:left; 
    position:relative;
    background:#E6E6E8;
}


$('a.scrollToBottom').click(function(){
  $('html, body').stop().animate({
scrollTop: $("#topPage").offset().top
  }, 2000);
// event.preventDefault();
});

但是页面(topPage)从下到上滚动。我需要从上到下滚动才能显示在主屏幕区域。

4

2 回答 2

0

您的问题是div放置在负top偏移量处。您不能垂直滚动超过 0,因此一旦您到达顶部,滚动就会停止,您将无法看到所有div.

如果您想要div动画,请考虑使用

$('.topcontent').stop().animate({
    top: 0
}, 2000);

反而。

于 2012-10-22T06:34:30.920 回答
0

为了自动滚动动画到页面底部(或者,足以让整个页面在视口内),我使用这个:

  $(window.opera ? 'html' : 'body,html,document').animate({ 
    scrollTop: $('body').height() - $(window).height()) 
  }, 1000);
于 2012-10-22T07:58:27.137 回答