【发布时间】:2015-02-19 19:05:21
【问题描述】:
我正在谷歌搜索解决方案。并看到了一些解决方案,但没有人帮助我。当我在 chrome 中询问 height() 时。它返回我的真实值,它是 1627。但是当我在脚本中写入时,它将被更改为此。它返回给我 1290。我不知道为什么。如何从文档返回真实高度(因为窗口无法帮助我)。我正在尝试使用 height()、innerHeight() 和 outerHeight()。
这是我的问题的屏幕:http://www.speedyshare.com/hTUDt/1.png
$(document).ready(function(){
var menu = $("#menu").height();
var content = $("body").outerHeight(true);
if(menu != content)
{
menu = content;
$("#menu").css({'height':menu+'px'});
}
});
或者像这样
$(document).ready(function () {
var menu = $('#menu');
$(window).resize(function () {
var height = $('#body').height();
menu.css({
'height': height + 'px',
});
}).trigger('resize');
});
这行不通。
在 css 中我有:
#menu {
width: 15%;
/*height: 100%;*/
background: #F5F5F5;
padding-top: 1%;
/* padding-bottom: 1%; */
font-size: 1.6rem;
font-family: 'Lato';
font-weight: 300;
color: #969696;
position: absolute;
border-right: 1px solid #c5c5c5;
box-shadow: 0px -1px 0px 1px #fff;
}
在萤火虫中,我看到了发生了什么。他取身高值 1290(我不知道为什么)而不是实际身高或 1626
【问题讨论】:
-
试试
$('your_selector').prop('clientHeight');
标签: javascript jquery html css height