How to get the browser viewport size
P粉237029457
P粉237029457 2023-08-28 11:06:30
0
2
488

I want my visitors to be able to see high quality images, is there any way to detect the window size?

Or better yet, the viewport size of the browser using JavaScript? See the green area here:

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.innerWidtha> andwindow.innerHeight一个>

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

    document.documentElement .clientWidthand.clientHeight


    resource

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!