Skip to content

Instantly share code, notes, and snippets.

@masterT
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masterT/17e70b90e6fb67be8c6f to your computer and use it in GitHub Desktop.
Save masterT/17e70b90e6fb67be8c6f to your computer and use it in GitHub Desktop.
Fix HTML footer

THE FIXER (TEST)

asdfasdfasdfasdf
// old school js, back in the dayz yeah !
// grab some elements
var header = document.getElementsByTagName('header')[0];
var container = document.getElementById('container');
var footer = document.getElementsByTagName('footer')[0];
function updateFooter () {
// if the content height is bigger than the window height
if (window.screen.height < (container.clientHeight + header.clientHeight + footer.clientHeight)){
// unfixe the footer
if (footer.classList.contains("fixed")){
footer.classList.remove("fixed");
}
}
else{
// fixe the footer
if (footer.classList.contains("fixed") == false){
footer.classList.add("fixed");
}
}
}
// resize the footer on load
window.addEventListener('load', function(){
updateFooter();
}, false);
// add event on window resizin'
window.onresize = function () {
updateFooter();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment