浏览器尺寸(宽和高) [英] Browser size (width and height)

查看:87
本文介绍了浏览器尺寸(宽和高)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来检测浏览器的当前大小(宽度和高度)。我知道这是jQuery的超级容易与的$(document).WIDTH和的$(document).height ,但我并不想对jQuery 11b的尺寸加入这个项目,所以我宁愿只使用内置在JavaScript中。什么会做同样的事情用JavaScript短而有效的方式?


解决方案

  //首先从窗口大小
//如果不奏效,从身体得到它
变种大小= {
  宽度:window.innerWidth || document.body.clientWidth,
  高度:window.innerHeight || document.body.clientHeight
}

I'm trying to detect the browser's current size (width and height). I know it's super easy in jQuery with $(document).width and $(document).height, but I don't want to add the size of the jQuery lib to the project, so I'd rather just use built in JavaScript. What would be the short and efficient way to do the same thing with JavaScript?

解决方案

// first get the size from the window
// if that didn't work, get it from the body
var size = {
  width: window.innerWidth || document.body.clientWidth,
  height: window.innerHeight || document.body.clientHeight
}

这篇关于浏览器尺寸(宽和高)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆