jQuery 获取浏览器窗口尺寸

使用 jQuery 获取浏览器窗口宽度和高度的方法:

1. jQuery.width() 和 jQuery.height():获取可视区域的尺寸,不包括滚动条。

2. jQuery.innerWidth() 和 jQuery.innerHeight():获取内容区域的尺寸,包括滚动条。

3. jQuery.outerWidth() 和 jQuery.outerHeight():获取元素的完整尺寸,包括边框和内边距。

4. jQuery.offset():获取元素相对于文档的偏移量,其中 top 和 left 属性表示窗口相对于元素的偏移量。

方法对比:

| 方法 | 获取的尺寸 | 包含滚动条 | 包含边框和内边距 |

|---|---|---|---|

| jQuery.width() | 可视区域 | 否 | 否 |

| jQuery.innerWidth() | 内容区域 | 是 | 否 |

| jQuery.outerWidth() | 元素完整尺寸 | 否 | 是 |

| jQuery.offset() | 相对于文档的偏移量 | 无关 | 无关 |

docx 文件大小:15.57KB