Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

javascript - 使用JavaScript获取浏览器视口尺寸(Get the browser viewport dimensions with JavaScript)

I want to provide my visitors the ability to see images in high quality, is there any way I can detect the window size? (我想为访问者提供观看高质量图像的能力,有什么方法可以检测窗口大小吗?)

Or better yet, the viewport size of the browser with JavaScript? (或者更好的是,使用JavaScript的浏览器的视口大小?) See green area here: (在此处查看绿色区域:)

  ask by Alix Axel translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Cross-browser) @media (width) and @media (height) values (跨浏览器的) @media (width)@media (height)值)

var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

window.innerWidth and .innerHeight (window.innerWidth.innerHeight)

  • gets CSS viewport @media (width) and @media (height) which include scrollbars (获取CSS视口 @media (width)@media (height) ,其中包括滚动条)
  • initial-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 values (initial-scale和缩放变化可能会导致移动值错误地)缩小到PPK称为可视视口的值,并且小于@media值)
  • zoom may cause values to be 1px off due to native rounding (缩放可能会由于本机舍入而导致值偏离1像素)
  • undefined in IE8- (在IE8中undefined)

document.documentElement.clientWidth and .clientHeight (document.documentElement.clientWidth.clientHeight)

Resources (资源资源)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...