Last active
August 29, 2015 14:00
-
-
Save martynchamberlin/11389322 to your computer and use it in GitHub Desktop.
Sticky footer for complex case scenarios where other intruding DOM elements keep us from being able to use Ryan Fait's footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<!-- the fact that this main block has an ID of #wrap has no actual bearing on this plugin --> | |
<div id="wrap">Main site content goes here, though the div doesn't | |
really have to close before footer begins. That doesn't matter either | |
way, which is what I think makes this solution so beautiful. | |
</div> | |
<footer>Copyright 2014</footer> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function( $ ) | |
{ | |
function sticky_footer( initialize ) | |
{ | |
if ( initialize ) | |
{ | |
$('footer').wrap('<div class="footer-wrap"></div>'); | |
} | |
// Remove the class real quick so we can "test" it to see if | |
// we really still need it | |
$('.footer-wrap').removeClass('absolute'); | |
var f_offset = $('.footer-wrap').offset(); | |
var f_height = $('.footer-wrap').outerHeight(); | |
if ( f_offset.top + f_height < $(window).height() ) | |
{ | |
$('.footer-wrap').addClass('absolute'); | |
} | |
else | |
{ | |
$('.footer-wrap').removeClass('absolute'); | |
} | |
} | |
sticky_footer( true ); | |
$(window).resize(function() | |
{ | |
sticky_footer( false ); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.footer-wrap.absolute { | |
position: absolute; | |
bottom: 0; | |
width: 100%; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment