JavaScript Apply Max-Width (in Pixels) in IE


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var maxWidth = '750'; // Max width of area to be resized
  2. var content_area_id = ''; // ID of the element to be resized
  3.  
  4. var resizeTimeout = null;
  5.  
  6. function fixWidth() {
  7. var visibleArea = document.documentElement.clientWidth;
  8. if (visibleArea > maxWidth) {
  9. document.getElementById(content_area_id).style.width = maxWidth;
  10. } else {
  11. document.getElementById(content_area_id).style.width = visibleArea;
  12. }
  13. }
  14.  
  15. function addLoadEvent(func) {
  16. var oldonload = window.onload;
  17. if (typeof window.onload != 'function') {
  18. window.onload = func;
  19. } else {
  20. window.onload = function() {
  21. if (oldonload) {
  22. oldonload();
  23. }
  24. func();
  25. }
  26. }
  27. }
  28.  
  29. window.onresize=function(){
  30. if (resizeTimeout) {
  31. window.clearInterval(resizeTimeout);
  32. }
  33. resizeTimeout = setTimeout(fixWidth, 500);
  34. }
  35.  
  36. addLoadEvent(fixWidth);

URL: http://www.addedbytes.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.