Window.innerHeight - Web APIs 编辑

The read-only innerHeight property of the Window interface returns the interior height of the window in pixels, including the height of the horizontal scroll bar, if present.

The value of innerHeight is taken from the height of the window's layout viewport. The width can be obtained using the innerWidth property.

Syntax

let intViewportHeight = window.innerHeight;

Value

An integer value indicating the window's layout viewport height in pixels. The property is read only and has no default value.

To change the width of the window, call one of its resize methods, such as resizeTo() or resizeBy().

Usage notes

To obtain the height of the window minus its horizontal scroll bar and any borders, use the root <html> element's clientHeight() property instead.

Both innerHeight and innerWidth are available on any window or any object that behaves like a window, such as a tab or frame.

Example

Assuming a frameset

var intFrameHeight = window.innerHeight; // or

var intFrameHeight = self.innerHeight;
// will return the height of the frame viewport within the frameset

var intFramesetHeight = parent.innerHeight;
// will return the height of the viewport of the closest frameset

var intOuterFramesetHeight = top.innerHeight;
// will return the height of the viewport of the outermost frameset

FIXME: link to an interactive demo here

To change the size of a window, see window.resizeBy() and window.resizeTo().

To get the outer height of a window, i.e. the height of the whole browser window, see window.outerHeight.

Graphical example

The following figure shows the difference between outerHeight and innerHeight.

innerHeight vs outerHeight illustration

Specifications

SpecificationStatusComment
CSS Object Model (CSSOM) View Module
The definition of 'window.innerHeight' in that specification.
Working DraftInitial definition

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:119 次

字数:4464

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文