获取占x滚动条高度的窗口内部高度

get window inner height accounting for x scroll bar height

本文关键字:高度 内部 窗口 滚动条 获取      更新时间:2023-12-21

我需要得到窗口的内部高度,同时考虑x滚动条。但似乎CCD_ 1返回相同的高度,而不管CCD_。

有没有其他方法可以获得窗口高度,包括x-scroll条。

这个jsFiddle演示了当添加或删除滚动条时,值不会改变。应该有一个差值,它等于滚动条的高度。我也会把它的代码放在下面。非常感谢。

JavaScript:

$('#innerHeight').html(window.innerHeight);
$('input').click(function () {
    if ($('#bar').is(':visible')) {
        $('#bar').hide();
        $(this).val('show x-scroll bar');
        $('#innerHeight').html(inner.innerHeight);
    } else {
        $('#bar').show();
        $(this).val('hide x-scroll bar');
        $('#innerHeight').html(window.innerHeight);   
    }
});

HTML:

<input type="button" value="show x-scroll bar" /><br />
<div id="bar"></div>
<p>inner height: <a id = "innerHeight"> px</a></p>

据此,window.innerHeight包括滚动条的高度。我修改了您的示例以使用$(window).height(新的JSFiddle),如果选择了较新版本的jQuery,它就可以工作。我进入了jQuery 2.0.3,$(window)相当于window.document.documentElement.clientHeight

你可能也会发现这个讨论很有用。