2017-04-20 89 views
0

我有一个棘手的页脚这是目前关闭屏幕:粘页脚开始关闭屏幕

<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' 
     }); 
    } 
}); 

在页脚视后开始的那一刻,所以你必须向下滚动才能看到它。我怎样才能将它拉起来,使它位于视口内?

+0

您是否有兴趣在[纯CSS解决方案(https://css-tricks.com/couple-takes-sticky-footer/)呢? – Blazemonger

回答

0

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

看看这个codepen