Skip to content

Instantly share code, notes, and snippets.

@froop
Created January 13, 2012 05:20
Show Gist options
  • Save froop/1604802 to your computer and use it in GitHub Desktop.
Save froop/1604802 to your computer and use it in GitHub Desktop.
[JavaScript] ウィンドウのリサイズに合わせてコンテンツの高さを調整
function resizeContents() {
var contentsElem = document.getElementById("contents"),
headerElem = document.getElementById("header"),
parentH = contentsElem.offsetParent.clientHeight,
headerH = headerElem.offsetHeight,
paddingH = 10 * 2;
try {
contentsElem.style.height = (parentH - headerH - paddingH) + "px";
} catch (e) {
// ignore error
}
}
window.onload = function () {
resizeContents();
};
window.onresize = function () {
resizeContents();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment