Javascript screen.availHeight 和 window.height() 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3044230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between screen.availHeight and window.height()
提问by Akshay
I am executing the following Javascript on my browser (Firefox).
我正在我的浏览器 (Firefox) 上执行以下 Javascript。
console.debug("Screen height = "+ screen.availHeight); //outputs 770
console.debug("Window Height ="+ $(window).height()); //outputs 210(I am using jQuery as well)
console.debug("屏幕高度 = "+ screen.availHeight); //输出770
console.debug("窗口高度="+ $(window).height()); //输出210(我也在使用 jQuery)
What is the difference between the two? Is 770 in pixels and 210 in mm?
两者有什么区别?是 770 像素和 210 毫米?
Similarly, when I write $(document).height()and $(window).height(), there is a difference. What is the reason?
同样,当我写$(document).height()和 时$(window).height(),也有区别。是什么原因?
回答by jigfox
window.outerHeight
window.outerHeight
It's the height of the window on screen, it includes the page and all the visible browser's bars (location, status, bookmarks, window title, borders, …).
它是窗口在屏幕上的高度,它包括页面和所有可见的浏览器栏(位置、状态、书签、窗口标题、边框等)。
This notthe same as jQuery's $(window).outerHeight().
这不一样jQuery的$(window).outerHeight()。
window.innerHeightor $(window).height()
window.innerHeight或者 $(window).height()
It's the height of the viewport that shows the website, just the content, no browser's bars.
它是显示网站的视口的高度,只是内容,没有浏览器的栏。
document.body.clientHeightor $(document).height()
document.body.clientHeight或者 $(document).height()
It's the height of your document shown in the viewport. If it is higher than $(window).height()you get the scrollbars to scroll the document.
它是您的文档在视口中显示的高度。如果它高于$(window).height()你得到滚动条来滚动文档。
screen.availHeight
screen.availHeight
It's the height the browser's window can have if it is maximized, including the browser's bars. So when the window is maximized, screen.availHeight === window.outerHeight
这是浏览器窗口在最大化时可以具有的高度,包括浏览器的栏。所以当窗口最大化时,screen.availHeight === window.outerHeight
screen.height
screen.height
It simply matches the screen's resolution. So on a 1920×1080 screen, screen.heightwill be 1080.
它只是匹配屏幕的分辨率。所以在 1920×1080 的屏幕上,screen.height将是1080.
screen.availHeightis equal to [screen.height+ the operating system's bars], like the taskbar on Windows, the dock and menu on OS X, or whatever is fixed on top or bottom of your screen if you're using Linux.
screen.availHeight等于 [ screen.height+ 操作系统的栏],例如 Windows 上的任务栏、OS X 上的 Dock 和菜单,或者如果您使用的是 Linux,则固定在屏幕顶部或底部的任何内容。

