Advertisement
Guest User

Untitled

a guest
Dec 7th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Sticky Footer</title>
  5. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  6.  
  7. <style>
  8. body{ margin:0; padding:0; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#FFF; text-align:center; }
  9. #top-bar{ height:32px; width:100%; background:#333; }
  10. #header{ height:160px; width:100%; background:#ccc; }
  11. #wrapper{ width:600px; margin:0 auto; }
  12. .container{ height:500px; width:390px; background:#BCF2FC; float:left; }
  13. .sidebar{ height:500px; width:200px; background:#999; float:right; }
  14. .clear:after{ content: "."; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; margin-bottom:30px; }
  15. #footer{ background:#666; height: 146px; width: 100%; }
  16.    
  17. </style>
  18.  
  19. <script type="text/javascript">
  20. $(window).bind("load", function() {
  21.  
  22.        var footerHeight = 0,
  23.            footerTop = 0,
  24.            $footer = $("#footer");
  25.  
  26.        positionFooter();
  27.  
  28.        function positionFooter() {
  29.  
  30.                 footerHeight = $footer.height();
  31.                 footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px";
  32.  
  33.                if ( ($(document.body).height()+footerHeight) < $(window).height()) {
  34.                   $footer.css({
  35.                        position: "absolute"
  36.                   }).animate({
  37.                        top: footerTop
  38.                   })
  39.               } else {
  40.                   $footer.css({
  41.                        position: "static"
  42.                   })
  43.               }
  44.  
  45.       }
  46.  
  47.       $(window)
  48.               .scroll(positionFooter)
  49.               .resize(positionFooter)
  50.  
  51. });
  52.  
  53. </script>
  54. </head>
  55. <body>
  56.  
  57.  
  58. <div id="top-bar">top-bar content</div>
  59. <div id="header">header</div>
  60.  
  61. <div id="wrapper">
  62.     <div class="container">container</div>
  63.     <div class="sidebar">sidebar</div>
  64. </div>
  65.  
  66. <div class="clear"></div>
  67.  
  68. <div id="footer">
  69.     Sticky Footer
  70. </div>
  71.  
  72.  
  73. </body>
  74. </html>
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement