元素设置为自动高度

  1. /* 
  2.     将具有 autoheight 属性的 div 元素设置为自动高度 
  3.      
  4.     用法:给需要的 div 元素添加 autoheight 属性,如:<div autoheight> ... </div> 
  5.           可以修改选择符,如写为 ".autoheight" 或是其它的以匹配需要的元素。 
  6.      
  7. */  
  8.   
  9. $(function () {  
  10.     var _jahDivs = $("div[autoheight]");  
  11.     if (_jahDivs.length > 0) {  
  12.         _jahDivs.css("overflow""auto");  
  13.         $(window).resize(function () {  
  14.             var _addHeight = $(window).height() - $("body").outerHeight(true);  
  15.             var _height = _jahDivs.height();  
  16.             _jahDivs.height(_height + _addHeight - (_jahDivs.outerHeight(true) - _height) / 2);  
  17.         }).resize();  
  18.     }  
  19. }); 
posted @ 2014-03-29 11:12  Tsy_blog  阅读(337)  评论(0)    收藏  举报