【发布时间】:2016-03-14 07:58:42
【问题描述】:
我有这个问题很可能很容易解决,但我是 JS/JQuery 的新手。 我有这段代码(参见这里的小提琴:https://jsfiddle.net/Tiph/6ep3hp4j/),当滚动条到达文档底部时,我的 div 页脚会显示,但我希望它显示滚动条何时到达我的页眉下方的某个高度并具有固定位置在我的窗口底部。我知道我必须用 window.height 和/的 offsetTop 计算一些东西,但没有任何效果。 有人可以帮我吗? 太感谢了! :-)
我的代码在这里:
var footer = $('#footer'),
extra = 10;
footer.css({ opacity: '0', display: 'block' });
$(window).scroll(function() {
var scrolledLength = ( $(window).height() + extra ) + $(window).scrollTop(),
documentHeight = $(document).height();
console.log( 'Scroll length: ' + scrolledLength + ' Document height: ' + documentHeight )
if( scrolledLength >= documentHeight ) {
footer
.addClass('bottom')
.stop().animate({ bottom: '0', opacity: '1' }, 300);
}
else if ( scrolledLength <= documentHeight && footer.hasClass('bottom') ) {
footer
.removeClass('bottom')
.stop().animate({ bottom: '-100', opacity: '0' }, 300);
}
});
【问题讨论】:
-
问题是它把你的内容隐藏在了底部?
标签: javascript jquery scrolltop