Posted By

jamesming on 10/13/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jamesming


Auto Resize div according to windows size.


 / Published in: JavaScript
 

URL: http://blondr.blogspot.com/2006/12/auto-resize-div-according-to-windows.html

  1. function getObj(name){
  2. if (document.getElementById){
  3. this.obj = document.getElementById(name);
  4. this.style = document.getElementById(name).style;
  5. }
  6. else if (document.all){
  7. this.obj = document.all[name];
  8. this.style = document.all[name].style;
  9. }
  10. }
  11.  
  12. function getWinSize(){
  13. var iWidth = 0, iHeight = 0;
  14.  
  15. if (document.documentElement && document.documentElement.clientHeight){
  16. iWidth = parseInt(window.innerWidth,10);
  17. iHeight = parseInt(window.innerHeight,10);
  18. }
  19. else if (document.body){
  20. iWidth = parseInt(document.body.offsetWidth,10);
  21. iHeight = parseInt(document.body.offsetHeight,10);
  22. }
  23.  
  24. return {width:iWidth, height:iHeight};
  25. }
  26.  
  27. function resize_id(obj) {
  28. var oContent = new getObj(obj);
  29. var oWinSize = getWinSize();
  30. if ((oWinSize.height - parseInt(oContent.obj.offsetTop,10))>0)
  31. oContent.style.height = (oWinSize.height - parseInt(oContent.obj.offsetTop,10));
  32. }
  33.  
  34. window.onresize = function() { resize_id('ID_of_Container'); }

Report this snippet  

You need to login to post a comment.