Last active
February 24, 2016 18:45
-
-
Save avantegarde/3b8f0889058802c45ff6 to your computer and use it in GitHub Desktop.
Auto adjust the padding at the top of the site to match the header height for fixed header bars. Also set a min-height for the main content area so the footer gets pushed to the bottom of the browser window if page is shorter.
This file contains hidden or 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
/*************************************************************************/ | |
/* Auto-Sizing header, footer, hero caption text | |
/*************************************************************************/ | |
// Page top padding based on height of the header | |
function autoHeaderHeight() { | |
var header = document.getElementsByClassName("navbar-fixed-top")[0]; | |
var pageBody = document.getElementsByClassName("content-area")[0]; | |
if (header && pageBody){ | |
var headerHeight = header.clientHeight; | |
pageBody.style.paddingTop = headerHeight + "px"; | |
} | |
} | |
window.addEventListener("resize", autoHeaderHeight); | |
window.addEventListener("load", autoHeaderHeight); | |
// Auto Page Height for small pages | |
function autoPageHeight() { | |
var footer = document.getElementsByClassName("site-footer")[0]; | |
var pageBody = document.getElementsByClassName("content-area")[0]; | |
if (footer && pageBody){ | |
var footerHeight = footer.clientHeight; | |
var pageHeight = window.innerHeight - footerHeight; | |
pageBody.style.minHeight = pageHeight + "px"; | |
} | |
} | |
window.addEventListener("resize", autoPageHeight); | |
window.addEventListener("load", autoPageHeight); | |
// Auto center the caption box vertically over the hero image | |
function centerCaption() { | |
var hero = document.getElementsByClassName("center-hero")[0]; | |
var caption = document.getElementsByClassName("hero-caption")[0]; | |
if (hero && caption){ | |
var heroHeight = hero.clientHeight; | |
var captionHeight = caption.clientHeight; | |
var centerHeight = (heroHeight - captionHeight) / 2; | |
caption.style.top = centerHeight + "px"; | |
} else if (caption) { | |
caption.style.top = "0"; | |
} | |
} | |
window.addEventListener("resize", centerCaption); | |
window.addEventListener("load", centerCaption); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment