@media (width)
和@media (width)
值@media (height)
@media (height)
和var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
window.innerWidth
.innerHeight
和CSS viewport@media (width)
和缩放@media (height)
可能导致移动值错误地缩小到PPK所称的initial-scale
,并且小于variations值@media
和undefined
document.documentElement.clientWidth
和.clientHeight
@media (width)
@media (height)
其中same as 调用浏览器视口jQuery(window).width()
可以在移动设备上的虚拟像素中提供正确的值
[matchMedia
和jQuery dimension functions
您可以使用$(window).width()
和$(window).height()
属性。
var elem = (document.compatMode === "CSS1Compat") ?
document.documentElement :
document.body;
var height = elem.clientHeight;
var width = elem.clientWidth;
。我在现有网站上工作,被“响应”,需要迫使更大的浏览器使用不同的元视口。 function myFunction(){
if(window.innerWidth !== undefined && window.innerHeight !== undefined) {
var w = window.innerWidth;
var h = window.innerHeight;
} else {
var w = document.documentElement.clientWidth;
var h = document.documentElement.clientHeight;
}
var txt = "Page size: width=" + w + ", height=" + h;
document.getElementById("demo").innerHTML = txt;
}
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}
和console.log('viewport width'+viewport().width);
之间存在差异。第一个包括水平滚动条的高度。