search

Home  >  Q&A  >  body text

How to get the browser viewport size

<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粉237029457P粉237029457455 days ago594

reply all(2)I'll reply

  • P粉342101652

    P粉3421016522023-08-29 09:50:47

    jQuery Dimension Function

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

    reply
    0
  • P粉955063662

    P粉9550636622023-08-29 00:22:49

    Cross-browser @media(width)< /code> and @media(height) 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 and window.innerHeight

    • GetCSS viewport @media(width)< /code> 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

    reply
    0
  • Cancelreply