JQuery (document) .width () does not include width outside the visible area

jQuery(document).width()does not include the total width (visible + out of visible when there is a horizontal strip). He is equal jQuery(window).width(). I thought that jQuery(window).width()is the width of the visible region, and jQuery(document).width()is the total width.

How to get the total width or how to get the width of the area outside the visible area using jQuery?

+3
source share
4 answers

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

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

JsFiddle example

alt text


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

Chrome, Firefox, Internet Explorer Safari.

+7

, jQuery,

document.getElementsByTagName('body')[0].offsetWidth

, .

+2

That's my fault. I showed the width, and then there was code somewhere after that that adjusted the width of some elements, which led to the expansion of the document.

0
source

I think these codes are also useful:

self.innerWidth && (document.documentElement && document.documentElement.clientWidth) && document.body.clientWidth;
0
source

Source: https://habr.com/ru/post/1765003/


All Articles