粘性页脚从屏幕开始

  • 本文关键字:屏幕 开始 jquery
  • 更新时间 :
  • 英文 :


我有一个粘性页脚,目前正在屏幕上:

<div id="footer"> <!-- Your footer here --> </div>

 $(window).bind("load", function () {
    var footer = $("#footer");
    var pos = footer.position();
    var height = $(window).height();
    height = height - pos.top;
    height = height - footer.height();
    if (height > 0) {
        footer.css({
            'margin-top': height + 'px'
        });
    }
});

目前页脚在视口之后开始,因此您必须向下滚动才能看到它。如何将其稍微向上拉,以便它位于视口内?

footer.height();更改为footer.innerHeight();

查看此Codepen

footer.outerHeight()替换footer.height()。然后使用$(document).ready而不是$(window).bind,因为.bind现在已弃用。

https://jsfiddle.net/mblase75/aj08qffx/

最新更新