Created
July 14, 2014 02:28
-
-
Save greycode/a04c370f6180ae309d18 to your computer and use it in GitHub Desktop.
根据窗口大小自动改变元素高度
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 将具有 autoheight 属性的 div 元素设置为自动高度 | |
| * 用法:给需要的 div 元素添加 autoheight 属性,如:<div autoheight> ... </div> | |
| * 可以修改选择符,如写为 ".autoheight" 或是其它的以匹配需要的元素。 | |
| */ | |
| $(function () { | |
| var _jahDivs = $("#textMsg"); | |
| 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(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment