How do I get a floating footer to stick to the bottom of the viewport in IE 6?

前端 未结 6 1871
感动是毒
感动是毒 2020-12-03 08:14

I know this would be easy with position:fixed, but unfortanately I\'m stuck with supporting IE 6. How can I do this? I would rather use CSS to be clean, but if I have to u

6条回答
  •  醉话见心
    2020-12-03 09:01

    $(function(){
        positionFooter(); 
        function positionFooter(){
            if($(document).height() < $(window).height()){//Without the body height conditional the footer will always stick to the bottom of the window, regardless of the body height, $(document).height() - could be main container/wrapper like $("#main").height() it depend on your code
                $("#footer").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$("#footer").height())+"px"})
            }   
        }
    
        $(window).scroll(positionFooter);
        $(window).resize(positionFooter);
    });
    

提交回复
热议问题