$(window).width()vs $(document).width()之间的区别 [英] Difference between $(window).width() vs $(document).width()
问题描述
$(窗口).width()
vs $(文档).width()$ c $之间的主要区别是什么? c>在jQuery中?
是否window表示浏览器,而document表示html页面的正文?我对么 ?
What is the major difference between $(window).width()
vs $(document).width()
in jQuery?
Whether window denotes the browser and document represents the body of html page? Am I correct ?
推荐答案
来自 width()
的文档:
From the documentation of width()
:
此方法也是能够找到窗口和文档的宽度。
This method is also able to find the width of the window and document.
$(window).width(); // returns width of browser viewport
$(document).width(); // returns width of HTML document
在演示中,我设置了 html {width:1000px; }
,大于视口。
In the demo, I have set html { width: 1000px; }
, which is bigger than the viewport.
HTML页面正文的宽度是第三个值。 $('body')。width()
也可以与其他两个不同(尝试 body {margin:100px;}
例如)。
The width of the body of your HTML page is a third value. $('body').width()
can also differ from the other two (try body { margin: 100px; }
for example).
这篇关于$(window).width()vs $(document).width()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!