views:

294

answers:

3

I am trying to make a sticky footer for my web page, I found some CSS that does keep the footer at the bottom but has a few downsides. 1, If you keep scrolling down the page the page just gets bigger and bigger (that was completely unexpected, no idea what caused that). 2 it moves down with the page in a jerky action, like stop..go..stop..go. Are there any tweaks or different code that might allow a smooth moving sticky footer to stay at the bottom of the page?

by the way, this code was oringaly for a static menu, I just adapted it for a sticky footer

Here's the javascript code,

<script type="text/javascript">
  // attribute added inline inside tag)

    var staticmenuids=["staticmenu"]

    var staticmenuoffsetY=[]

    function getmenuoffsetY(){
for (var i=0; i<staticmenuids.length; i++){
 var currentmenu=document.getElementById(staticmenuids[i])
 staticmenuoffsetY.push(isNaN(parseInt(currentmenu.style.top))? 0 :   
          parseInt(currentmenu.style.top))
       }
      initstaticmenu()
    }

 function initstaticmenu(){
   var iebody=(document.compatMode &&  
   document.compatMode!="BackCompat")?  
   document.documentElement : document.body
   var topcorner=(window.pageYOffset)? window.pageYOffset : iebody.scrollTop
   for (var i=0; i<staticmenuids.length; i++)
         document.getElementById(staticmenuids[i]).style.top=topcorner+staticmenuoffsetY[i]+"px");

       setTimeout("initstaticmenu()", 5)
    }

   if (window.addEventListener)
      window.addEventListener("load", getmenuoffsetY, false)
   else if (window.attachEvent)
      window.attachEvent("onload", getmenuoffsetY)
 </script>

The CSS:

.wireframemenu{
width: 99%;
height:60px;
position: absolute;
}


html>body .wireframemenu a{ /*Non IE rule*/
width: auto;
}

Now the sticky footer:

<div id="staticmenu" class="wireframemenu" style="top: 520px;">
</div>
+1  A: 

You don't need any javascript for just a sticky footer. Just take a look at the sticky footer I'm using on one of my sites: http://stackoverflow.com/questions/1394908/link-in-sticky-footer-not-clickable-in-firefox-and-chrome

jeroen
A: 

Best thing since sliced bread: http://www.cssstickyfooter.com/

PHLAK