我需要滚动内容从上到下的页面 并且导航具有“显示顶部”锚点。当我点击“显示顶部”锚点时,页面(之前未显示)将从内部滚动到主屏幕区域。
.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)从下往上滚动.. 我需要从上到下滚动显示在主屏幕区域。
答案 0 :(得分:0)
您的问题是div
的偏移量为top
。您无法垂直滚动0,因此滚动到顶部时滚动停止,您将无法看到所有div
。
如果您希望 div
设置动画,请考虑使用
$('.topcontent').stop().animate({
top: 0
}, 2000);
代替。
答案 1 :(得分:0)
要自动将动画滚动到页面底部(或者,整个页面都在视口内),我会使用:
$(window.opera ? 'html' : 'body,html,document').animate({
scrollTop: $('body').height() - $(window).height())
}, 1000);