Return to Snippet

Revision: 11410
at February 4, 2009 11:17 by DaveChild


Updated Code
var maxWidth = '750'; // Max width of area to be resized
var content_area_id = ''; // ID of the element to be resized

var resizeTimeout = null;

function fixWidth() {
	var visibleArea = document.documentElement.clientWidth;
	if (visibleArea > maxWidth) {
		document.getElementById(content_area_id).style.width = maxWidth;
	} else {
		document.getElementById(content_area_id).style.width = visibleArea;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onresize=function(){
	if (resizeTimeout) {
		window.clearInterval(resizeTimeout);
	}
	resizeTimeout = setTimeout(fixWidth, 500);
}

addLoadEvent(fixWidth);

Revision: 11409
at February 4, 2009 11:08 by DaveChild


Updated Code
var maxWidth = '750'; // Max width of area to be resized
var content_area_id = ''; // ID of the element to be resized

var resizeTimeout = null;

function fixWidth() {
	var visibleArea = document.body.offsetWidth;
	if (visibleArea > maxWidth) {
		document.getElementById(content_area_id).style.width = maxWidth;
	} else {
		document.getElementById(content_area_id).style.width = visibleArea;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onresize=function(){
	if (resizeTimeout) {
		window.clearInterval(resizeTimeout);
	}
	resizeTimeout = setTimeout(fixWidth, 500);
}

addLoadEvent(fixWidth);

Revision: 11408
at February 4, 2009 11:01 by DaveChild


Updated Code
var maxWidth = '750px'; // Max width of area to be resized
var content_area_id = ''; // ID of the element to be resized

var resizeTimeout = null;

function fixWidth() {
	var visibleArea = document.body.offsetWidth;
	if (visibleArea > maxWidth) {
		document.getElementById(content_area_id).style.width = maxWidth;
	} else {
		document.getElementById(content_area_id).style.width = visibleArea;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onresize=function(){
	if (resizeTimeout) {
		window.clearInterval(resizeTimeout);
	}
	resizeTimeout = setTimeout(fixWidth, 500);
}

addLoadEvent(fixWidth);

Revision: 11407
at February 4, 2009 10:48 by DaveChild


Updated Code
var resizeTimeout = null;
var maxWidth = '750px';

function fixWidth(content_area_id) {
	var visibleArea = document.body.offsetWidth;
	if (visibleArea > maxWidth) {
		document.getElementById(content_area_id).style.width = maxWidth;
	} else {
		document.getElementById(content_area_id).style.width = visibleArea;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onresize=function(){
	if (resizeTimeout) {
		window.clearInterval(resizeTimeout);
	}
	resizeTimeout = setTimeout(fixWidth, 500);
}

addLoadEvent(fixWidth);

Revision: 11406
at February 4, 2009 10:46 by DaveChild


Initial Code
var resizeTimeout = null;
var minWidth = '750px';

function fixWidth(content_area_id) {
	var visibleArea = document.body.offsetWidth;
	if (visibleArea < 750) {
		document.getElementById(content_area_id).style.width = minWidth;
	} else {
		document.getElementById(content_area_id).style.width = visibleArea;
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

window.onresize=function(){
	if (resizeTimeout) {
		window.clearInterval(resizeTimeout);
	}
	resizeTimeout = setTimeout(fixWidth, 500);
}

addLoadEvent(fixWidth);

Initial URL
http://www.addedbytes.com

Initial Description


Initial Title
JavaScript Apply Max-Width (in Pixels) in IE

Initial Tags
javascript

Initial Language
JavaScript