How to get the browser viewport size
P粉237029457
2023-08-28 11:06:30
<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>
jQuery Dimension Function
$(window).width()
and$(window).height()
Cross-browser
@media(width)
and@media(height)
a> valuewindow.innerWidth
a> andwindow.innerHeight
一个>@media(width) and
@media (height)
which includes scrollbarsinitial-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@media
valueUndefined in IE8
-document.documentElement .clientWidth
and.clientHeight
@media (width)
and@media (height)
jQuery(window).width()
jQuery Call Browser viewportresource
matchMedia
to get exact dimensions in any unit