$(window).width()vs $(document).width()之间的区别 [英] Difference between $(window).width() vs $(document).width()

查看:926
本文介绍了$(window).width()vs $(document).width()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(窗口).width() vs $(文档).width()在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


简单的jsFiddle演示

在演示中,我设置了 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆