【发布时间】:2019-04-04 21:17:48
【问题描述】:
当您在页面底部滚动时,我找不到如何停止固定在页脚 div 顶部的图像。
我尝试计算页脚高度以将其从 window.height 中删除以强制滚动停止在该点。
.footer-arrow 是我的固定图像。
下面的代码成功地做到了这一点:
$(function() {
$(window).scroll(function() {
var footHeight = $('#footer').offset().top;
var height = (($(window).height()) - footHeight);
// if ($(document).height() - footHeight <= ($(window).height() + $(window).scrollTop()))
if ($(this).scrollTop() > footHeight) {
$('.footer-arrow').css({
position: 'fixed',
bottom: 20
});
} else {
$('.footer-arrow').addClass('fixed');
$('.footer-arrow').css({
position: 'fixed',
bottom: 140,
});
}
})
});
【问题讨论】:
-
能否包含您的html?
标签: javascript jquery html css scroll