[英]JS “Window” width-height vs “screen” width-height?
当我看这段代码时,我有点想知道:
// Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
...
// Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
$(document).height();
有什么区别? 和$(window).height();
?
Window是顶层客户端object,包含文档。 这个 jsFiddle 显示$(window).height()
和$(document).height()
返回相同的值: http://jsfiddle.net/jackrugile/5xSuv/
如果我没记错的话,Window 是视口的大小,不包括任何 chrome 或浏览器界面。 我相信两者的值将始终相同,除非您在 window 中引用 iframe 之类的东西。
$(document).height
是视口的内部区域,基本上是从工具栏/url 栏的底部到状态栏/底部滚动条/window 的底部。 $(window).height
获取 window 的整个高度,包括地址栏和滚动条等内容。
@jackrugile 的 jsfiddle 代码为 document 和 window 返回相同的值,因为 jsfiddle 代码在 iframe 内运行。
如果不运行 iframe,为了使事情更清楚 -
希望它有所帮助并使事情更清楚。
屏幕——您的屏幕:尺寸值随您的显示器尺寸而变化。
screen.availWidth //There is no screen.height
Window 或文档——浏览器的 window(浏览器视口,不包括工具栏和滚动条)。 如果页面可滚动,则忽略不可见的可滚动部分。 IE9 及以上版本使用'window',很简单。
window.innerHeight //IE9, Chrome, Safari, Firefox
document.documentElement(or body).clientHeight //IE 8,7,6,5
注意:Window 和文档不一样。 文档 object(来自 DOM)是 Window object(来自 BOM)的属性。 但是给出相同的尺寸。 从 W3Schools 来看,我认为“Window”是新浏览器版本(IE9、Chrome、Firefox 等)的符号,而“document”是 IE 8、7、6、5 的符号。
http://www.w3schools.com/js/js_window.asp ,并在不同尺寸的显示器上使用简单的 aspx 页面测试了上述内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.