jQuery(document).width()不包含可见区域之外的宽度 [英] jQuery(document).width() doesn't include width outside of viewable area

查看:67
本文介绍了jQuery(document).width()不包含可见区域之外的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery(document).width()不包括总宽度(有水平条时,可见+在可见范围之外).它等于jQuery(window).width().我以为jQuery(window).width()是可见区域的宽度,而jQuery(document).width()是总宽度.

jQuery(document).width() doesn't include the total width (viewable + outside of viewable when there's a horizontal bar). It equals jQuery(window).width(). I thought jQuery(window).width() is the viewable area width and jQuery(document).width() is the total width.

如何使用jQuery获取总宽度或如何在可见区域之外获取区域的宽度?

How do I get the total width or how do I get the width of the area outside of the viewable area using jQuery?

推荐答案

要获取不可见"部分的宽度,只需从可见窗口宽度中减去文档总宽度即可:

To get the width of the "invisible" portion, simply subtract the total document width from the visible window width:

jQuery(document).width() - jQuery(window).width()

jsFiddle示例

就像您写的一样,$(document).width()是总宽度,$(window).width()是当前可见的宽度.

Like you write, $(document).width() is the total width, and $(window).width() is the width that is currently visible.

在最新的Chrome,Firefox,Internet Explorer和Safari中进行了测试.

Tested in the latest Chrome, Firefox, Internet Explorer, and Safari.

这篇关于jQuery(document).width()不包含可见区域之外的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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