在页脚Jquery处停止浮点DIV
我正在使用以下代码:在页脚Jquery处停止浮点DIV,jquery,css,Jquery,Css,我正在使用以下代码: $(window).scroll(function () { if (($(document).height() - $(window).scrollTop()) <= 500){ $("#content-5").css({ position: 'fixed', top: 'auto', bottom: '300px' }); } else if ($(window).scr
$(window).scroll(function () {
if (($(document).height() - $(window).scrollTop()) <= 500){
$("#content-5").css({
position: 'fixed',
top: 'auto',
bottom: '300px'
});
} else if ($(window).scrollTop() >= 30) {
$("#content-5").css({
position: 'fixed',
top: '30px',
bottom: 'auto'
});
}else{
$("#content-5").css({
position: 'absolute',
top: '30px',
bottom: 'auto'
});
}
});
这是演示
它的工作很好,但我不知道怎么做,float div content-5停在页脚。任何人都可以提供帮助吗?这是您的JSFIDLE,已使用解决方案进行了更新: 守则:
$(window).scroll(function () {
var maxScroll = $(window).height()-$("#footer").height()-$("#content-5").height();
if ($(window).scrollTop() >= maxScroll){
$("#content-5").css({
position: 'absolute',
top: 'auto',
bottom: '200px'
});
} else if ($(window).scrollTop() >= 30) {
$("#content-5").css({
position: 'fixed',
top: '0px',
bottom: 'auto'
});
}else{
$("#content-5").css({
position: 'absolute',
top: '30px',
bottom: 'auto'
});
}
});
将此添加到滚动事件:
演示:您可以获得页脚的顶部偏移:
var footer_top= $("#footer").offset().top;
然后你可以检查滚动条,如果它超过页脚顶部,你应该更改你的内容css,如下所示:
$("#content-5").css({
position: 'absolute',
top: footer_top,//this is important for exact place
bottom: 'auto'
});
为什么要浮动此div,因为它是绝对/固定的?是否希望向下滚动时content-5与页脚一起从屏幕上消失?是,在页脚上方消失或停止。您以前问过此问题。感谢所有的解决方案!
$("#content-5").css({
position: 'absolute',
top: footer_top,//this is important for exact place
bottom: 'auto'
});