/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);
URL: http://www.addedbytes.com