【发布时间】:2010-05-21 08:19:40
【问题描述】:
我正在为 iPad 开发一个网络应用程序,以在 Safari 中运行。我还没有 iPad 可以测试。有谁知道可用的屏幕尺寸 - 在 safari/ipad 控件的任何空间被占用后?
【问题讨论】:
标签: ipad mobile-safari
我正在为 iPad 开发一个网络应用程序,以在 Safari 中运行。我还没有 iPad 可以测试。有谁知道可用的屏幕尺寸 - 在 safari/ipad 控件的任何空间被占用后?
【问题讨论】:
标签: ipad mobile-safari
您应该只关注TN2262 并编写维度不变的代码。
如果您需要逻辑像素大小,document.body.client[Width|Height] 始终为 980×1208。
就可以使用的绝对像素而言,Mobile Safari 的导航栏大约占 78px,因此纵向为 768×946,横向为 1024×690。
也可以有一个键盘(纵向高度为 308 像素,横向高度为 397 像素)。
更新:以上绝对数字仅适用于 iOS 4.x 或更早版本。在 iOS 5.x 中,Apple 引入了标签栏,将导航栏 + 状态栏的高度增加到 96px。实际上,即使在 iOS 5.x 之前,书签栏的存在也会影响视口。
【讨论】:
所以 - 在我的 ipad(ipad1、ios 5.1.1)上,我得到的数字与上面略有不同。可能是因为标签和书签栏正在显示。
我的价值观:
所以我写了一个 javascript 小书签来获得一个肯定的结果。您可以通过电子邮件将其发送给自己,在 safari 中转到“about:blank”,创建书签,对其进行编辑并从电子邮件中剪切/粘贴此代码:)
当您运行小书签时,重新调整 div 的大小,直到它与窗口和 tada 匹配..
<pre><code>
javascript:( function(){
"use strict";
var bmIdVal = "ios_screen_res_test_bookmarklet";
var bmDivSize = {
w : 320,
h : 240
};
var vpMeta1 = document.createElement('meta');
vpMeta1.setAttribute("name","viewport");
vpMeta1.setAttribute("content",'initial-scale=1.0, user-scalable=no');
document.head.appendChild(vpMeta1);
function updateStatus(){
statusDiv.innerHTML = "div is " + bmDivSize.w + ',' + bmDivSize.h +
" doc body says: " + document.body.clientWidth + "," +
document.body.clientHeight;
}
function resizeBmDiv(wPx,hPx){
bmDivSize.w += wPx;
bmDivSize.h += hPx;
bmDiv.style.width=bmDivSize.w + "px";
bmDiv.style.height=bmDivSize.h + "px";
updateStatus();
}
var prevBmDiv = document.getElementById(bmIdVal);
if( prevBmDiv != null){
document.body.removeChild(prevBmDiv);
}
var bmDiv = document.createElement("div");
bmDiv.setAttribute("id",bmIdVal);
bmDiv.style.cssText =
"position:absolute;left:0px;top:0px;background-color: #0066FF";
bmDiv.style.width=bmDivSize.w + "px";
bmDiv.style.height=bmDivSize.h + "px";
var sizerB_w1 = document.createElement("button");
sizerB_w1.style.cssText = "width:64px;height:64px";
sizerB_w1.innerHTML="w+1";
sizerB_w1.onclick = function(evt){
resizeBmDiv(1,0);
};
var sizerB_w100 = document.createElement("button");
sizerB_w100.style.cssText = "width:64px;height:64px";
sizerB_w100.innerHTML="w+100";
sizerB_w100.onclick = function(evt){
resizeBmDiv(100,0);
};
var sizerB_h1 = document.createElement("button");
sizerB_h1.style.cssText = "width:64px;height:64px";
sizerB_h1.innerHTML="h+1";
sizerB_h1.onclick = function(evt){
resizeBmDiv(0,1);
};
var sizerB_h100 = document.createElement("button");
sizerB_h100.style.cssText = "width:64px;height:64px";
sizerB_h100.innerHTML="h+100";
sizerB_h100.onclick = function(evt){
resizeBmDiv(0,100);
};
var sizerDiv = document.createElement('div');
sizerDiv.appendChild(sizerB_w1);
sizerDiv.appendChild(sizerB_w100);
sizerDiv.appendChild(sizerB_h1);
sizerDiv.appendChild(sizerB_h100);
var sizerB_wm1 = document.createElement("button");
sizerB_wm1.style.cssText = "width:64px;height:64px";
sizerB_wm1.innerHTML="w-1";
sizerB_wm1.onclick = function(evt){
resizeBmDiv(-1,0);
};
var sizerB_wm100 = document.createElement("button");
sizerB_wm100.style.cssText = "width:64px;height:64px";
sizerB_wm100.innerHTML="w-100";
sizerB_wm100.onclick = function(evt){
resizeBmDiv(-100,0);
};
var sizerB_hm1 = document.createElement("button");
sizerB_hm1.style.cssText = "width:64px;height:64px";
sizerB_hm1.innerHTML="h-1";
sizerB_hm1.onclick = function(evt){
resizeBmDiv(0,-1);
};
var sizerB_hm100 = document.createElement("button");
sizerB_hm100.style.cssText = "width:64px;height:64px";
sizerB_hm100.innerHTML="h-100";
sizerB_hm100.onclick = function(evt){
resizeBmDiv(0,-100);
};
var sizerMDiv = document.createElement('div');
sizerMDiv.appendChild(sizerB_wm1);
sizerMDiv.appendChild(sizerB_wm100);
sizerMDiv.appendChild(sizerB_hm1);
sizerMDiv.appendChild(sizerB_hm100);
var statusDiv = document.createElement('div');
statusDiv.style.cssText = "color:white;";
bmDiv.appendChild(statusDiv);
bmDiv.appendChild(sizerDiv);
bmDiv.appendChild(sizerMDiv);
document.body.appendChild(bmDiv);
updateStatus();
})();
</code></pre>
【讨论】:
【讨论】:
我编辑了 Andy Idsinga 的答案,创建了一个 HTML 文档,您可以上传到任何地方并在您的设备上运行。我已经更正了视口元标记并在屏幕旋转时设置了自动重新加载。我还添加了 w+10、w-10、h+10、h-10 按钮。如果你喜欢这篇文章,也请给 Andy 点个赞,因为他是原作者!
<html><head>
<title>Screen resolution test (usable area)</title>
</head><body>
<script type="text/javascript">
"use strict";
var bmIdVal = "ios_screen_res_test_bookmarklet";
var bmDivSize = {
w : 320,
h : 240
};
var vpMeta1 = document.createElement('meta');
vpMeta1.setAttribute("name","viewport");
vpMeta1.setAttribute("content",'initial-scale=1.0, maximum-scale=1.0');
document.head.appendChild(vpMeta1);
function updateStatus(){
statusDiv.innerHTML = "div is " + bmDivSize.w + ',' + bmDivSize.h +
" doc body says: " + document.body.clientWidth + "," +
document.body.clientHeight;
}
function resizeBmDiv(wPx,hPx){
bmDivSize.w += wPx;
bmDivSize.h += hPx;
bmDiv.style.width=bmDivSize.w + "px";
bmDiv.style.height=bmDivSize.h + "px";
updateStatus();
}
var prevBmDiv = document.getElementById(bmIdVal);
if( prevBmDiv != null){
document.body.removeChild(prevBmDiv);
}
var bmDiv = document.createElement("div");
bmDiv.setAttribute("id",bmIdVal);
bmDiv.style.cssText = "position:absolute;left:0px;top:0px;background-color: #0066FF";
bmDiv.style.width=bmDivSize.w + "px";
bmDiv.style.height=bmDivSize.h + "px";
var sizerB_w1 = document.createElement("button");
sizerB_w1.style.cssText = "width:64px;height:64px";
sizerB_w1.innerHTML="w+1";
sizerB_w1.onclick = function(evt){
resizeBmDiv(1,0);
};
var sizerB_w100 = document.createElement("button");
sizerB_w100.style.cssText = "width:64px;height:64px";
sizerB_w100.innerHTML="w+100";
sizerB_w100.onclick = function(evt){
resizeBmDiv(100,0);
};
var sizerB_h1 = document.createElement("button");
sizerB_h1.style.cssText = "width:64px;height:64px";
sizerB_h1.innerHTML="h+1";
sizerB_h1.onclick = function(evt){
resizeBmDiv(0,1);
};
var sizerB_h100 = document.createElement("button");
sizerB_h100.style.cssText = "width:64px;height:64px";
sizerB_h100.innerHTML="h+100";
sizerB_h100.onclick = function(evt){
resizeBmDiv(0,100);
};
var sizerDiv = document.createElement('div');
sizerDiv.appendChild(sizerB_w1);
sizerDiv.appendChild(sizerB_w100);
sizerDiv.appendChild(sizerB_h1);
sizerDiv.appendChild(sizerB_h100);
var sizerB_wm1 = document.createElement("button");
sizerB_wm1.style.cssText = "width:64px;height:64px";
sizerB_wm1.innerHTML="w-1";
sizerB_wm1.onclick = function(evt){
resizeBmDiv(-1,0);
};
var sizerB_wm100 = document.createElement("button");
sizerB_wm100.style.cssText = "width:64px;height:64px";
sizerB_wm100.innerHTML="w-100";
sizerB_wm100.onclick = function(evt){
resizeBmDiv(-100,0);
};
var sizerB_hm1 = document.createElement("button");
sizerB_hm1.style.cssText = "width:64px;height:64px";
sizerB_hm1.innerHTML="h-1";
sizerB_hm1.onclick = function(evt){
resizeBmDiv(0,-1);
};
var sizerB_hm100 = document.createElement("button");
sizerB_hm100.style.cssText = "width:64px;height:64px";
sizerB_hm100.innerHTML="h-100";
sizerB_hm100.onclick = function(evt){
resizeBmDiv(0,-100);
};
var sizerMDiv = document.createElement('div');
sizerMDiv.appendChild(sizerB_wm1);
sizerMDiv.appendChild(sizerB_wm100);
sizerMDiv.appendChild(sizerB_hm1);
sizerMDiv.appendChild(sizerB_hm100);
var sizerC_w10 = document.createElement("button");
sizerC_w10.style.cssText = "width:64px;height:64px";
sizerC_w10.innerHTML="w+10";
sizerC_w10.onclick = function(evt){
resizeBmDiv(10,0);
};
var sizerC_h10 = document.createElement("button");
sizerC_h10.style.cssText = "width:64px;height:64px";
sizerC_h10.innerHTML="h+10";
sizerC_h10.onclick = function(evt){
resizeBmDiv(0,10);
};
var sizerC_Mw10 = document.createElement("button");
sizerC_Mw10.style.cssText = "width:64px;height:64px";
sizerC_Mw10.innerHTML="w-10";
sizerC_Mw10.onclick = function(evt){
resizeBmDiv(-10,0);
};
var sizerC_Mh10 = document.createElement("button");
sizerC_Mh10.style.cssText = "width:64px;height:64px";
sizerC_Mh10.innerHTML="h-10";
sizerC_Mh10.onclick = function(evt){
resizeBmDiv(0,-10);
};
var sizerCDiv = document.createElement('div');
sizerCDiv.appendChild(sizerC_w10);
sizerCDiv.appendChild(sizerC_h10);
sizerCDiv.appendChild(sizerC_Mw10);
sizerCDiv.appendChild(sizerC_Mh10);
var statusDiv = document.createElement('div');
statusDiv.style.cssText = "color:white;";
bmDiv.appendChild(statusDiv);
bmDiv.appendChild(sizerDiv);
bmDiv.appendChild(sizerMDiv);
bmDiv.appendChild(sizerCDiv);
document.body.appendChild(bmDiv);
updateStatus();
window.onresize = function(event) {
document.location.reload(true);
}
</script>
</body></html>
【讨论】:
以上答案是错误的。 ipad header的实际大小是64px。 因此,ipad的纵向是= 768X960,横向是= 1024x704 您还可以检查 ipad 在纵向和横向方向的总尺寸,包括标题高度为 64px,然后它将纵向和横向显示为 768x1024
【讨论】:
上面的“正确”答案实际上是错误的,因为它没有考虑到 ipad 屏幕顶部的黑色状态栏显示时间、电池寿命等。这是一个额外的 18px 屏幕占用.
所以 Safari 中可用的屏幕区域实际上是: 风景:1024x672 肖像:768x928
【讨论】:
只需检查http://benfrain.com/downloads/respond.html 即可查看视口的当前尺寸。
或者更好地使用这个书签: http://lab.maltewassermann.com/viewport-resizer/ 这将显示所有类型设备的当前尺寸(也可以定制)。可以在每个网站上进行测试。
【讨论】: