我有一个粘性页脚,目前正在屏幕上:
<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/