TL;DR: Use document.documentElement.clientHeight/Width
This is not exactly an answer to the question, but it's helpful information if you're trying to do things based on the size of the document shown in the browser.
window.innerWidth
(and height) can get wacky on mobile browsers, even when you use the proper viewport meta tags. On some browsers it can be very inconsistent.
screen.width
works better for mobile browsers, but then you need to take into account orientation and whether or not the browser is mobile or desktop (if you need to be responsive for both), as screen.width
gives much more variation on desktop compared to window.innerWidth
.
In my experience, document.documentElement.clientWidth
is the best way to go. Mobile browsers are much more consistent for this attribute than for window.innerWidth
, and since you're dealing with the dimensions of the html element and not the browser window or the device screen, it's consistent between mobile and desktop, and orientation does not need to be accounted for.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…