How to get the browser viewport size
P粉237029457
P粉237029457 2023-08-28 11:06:30
0
2
602
<p>I want my visitors to be able to see high quality images, is there any way to detect the window size? </p> <p>Or better yet, the viewport size of the browser using JavaScript? See the green area here: </p>
P粉237029457
P粉237029457

reply all(2)
P粉342101652

jQuery Dimension Function

$(window).width() and $(window).height()

P粉955063662

Cross-browser @media(width) and @media(height) a> value

const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)

window.innerWidth a> and window.innerHeight一个>

  • GetCSS viewport @media(width) and @media (height) which includes scrollbars
  • initial-scale and scaling changes may cause movement errors to scale down to a value where the PPK calls the visual viewport and is smaller than @mediavalue
  • Due to native rounding, scaling may cause values ​​to shrink by 1 pixel
  • Undefined in IE8-

document.documentElement .clientWidth and .clientHeight


resource

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template