What is the original JavaScript equivalent of jQuery $ (window) .width

I heard it offset.width , document.documentElement.clientWidth and window.innerWidth

I am wondering which projects I cannot use jQuery, which solution should I use?

+4
source share
3 answers
function windowWidth() { var docElemProp = window.document.documentElement.clientWidth, body = window.document.body; return window.document.compatMode === "CSS1Compat" && docElemProp || body && body.clientWidth || docElemProp; } 

Taken (and slightly modified from jQuery source:

https://github.com/jquery/jquery/blob/master/src/dimensions.js#L42

+3
source

Watch for yourself. He uses different things. document.documentElement.clientWidth among them.

It can also use document.body.clientWidth

+4
source

it

 window.innerWidth 

The above property returns the same value as $( window ).width() .

Live demo: http://jsfiddle.net/Jukh9/1/show/

However, IE8 does not implement this property ...

+1
source

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


All Articles