Skip to content

Instantly share code, notes, and snippets.

@e10a
Last active November 23, 2024 15:36
Show Gist options
  • Save e10a/a42a2c13d038240c2de7a15b3908ebcc to your computer and use it in GitHub Desktop.
Save e10a/a42a2c13d038240c2de7a15b3908ebcc to your computer and use it in GitHub Desktop.
_js
# get root url
window.location.origin
Cross-browser @media (width) and @media (height) values
let vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
let vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
window.innerWidth and window.innerHeight
gets CSS viewport @media (width) and @media (height) which include scrollbars
initial-scale and zoom variations may cause mobile values to wrongly scale down to what PPK calls the visual viewport and be smaller than the @media values
zoom may cause values to be 1px off due to native rounding
undefined in IE8-
document.documentElement.clientWidth and .clientHeight
equals CSS viewport width minus scrollbar width
matches @media (width) and @media (height) when there is no scrollbar
same as jQuery(window).width() which jQuery calls the browser viewport
available cross-browser
inaccurate if doctype is missing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment