本文介绍了如何获得浏览器视口尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想为访问者提供观看高质量图像的能力,有什么方法可以检测到窗口大小吗?I want to provide my visitors the ability to see images in high quality, is there any way I can detect the window size?或者更好的是,视口JavaScript浏览器的大小?在此处查看绿色区域:Or better yet, the viewport size of the browser with JavaScript? See green area here:推荐答案 跨浏览器 @media(宽度) 和 @media(高度) 值Cross-browser @media (width) and @media (height) values const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0) window.innerWidth 和 window.innerHeight 获取 CSS视口 @media(宽度)和 @media(高度),其中包括滚动条 初始比例并缩放变化可能会导致移动值错误地 缩小为PPK称为视觉视口,并且小于 @media 值 由于本地舍入,缩放可能导致值降低1px 未定义-window.innerWidth and window.innerHeightgets CSS viewport @media (width) and @media (height) which include scrollbarsinitial-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 valueszoom may cause values to be 1px off due to native roundingundefined in IE8- 等于CSS视口宽度减滚动条宽度 匹配 @media(宽度)和 @media(高度),如果没有没有滚动条 与 jQuery(window).width()相同,其中 jQuery 调用浏览器视口 可用的跨浏览器 如果缺少文档类型,则不准确equals CSS viewport width minus scrollbar widthmatches @media (width) and @media (height) when there is no scrollbarsame as jQuery(window).width() which jQuery calls the browser viewportavailable cross-browserinaccurate if doctype is missing 各种尺寸的实时输出 verge 使用跨浏览器视口技术 实际 使用 matchMedia 以获得任何单位的精确尺寸Live outputs for various dimensionsverge uses cross-browser viewport techniquesactual uses matchMedia to obtain precise dimensions in any unit 这篇关于如何获得浏览器视口尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!