jQuery 插件:随窗口大小变化的自适应高度元素


严格说,这个不算是插件,做回标题党。



/*
	将具有 autoheight 属性的 div 元素设置为自动高度
	
	用法:给需要的 div 元素添加 autoheight 属性,如:
...
可以修改选择符,如写为 ".autoheight" 或是其它的以匹配需要的元素。 */ $(function () { var _jahDivs = $("div[autoheight]"); if (_jahDivs.length > 0) { _jahDivs.css("overflow", "auto"); $(window).resize(function () { var _addHeight = $(window).height() - $("body").outerHeight(true); var _height = _jahDivs.height(); _jahDivs.height(_height + _addHeight - (_jahDivs.outerHeight(true) - _height) / 2); }).resize(); } });

你可能感兴趣的:(JavaScript)