我正在测试我的Web应用程序在(Safari浏览器)和三星平板2 (默认浏览器)上。在这两个设备上,window.orientationchange返回不同的值。
$(document).ready(function() {
window.addEventListener("orientationchange", centerLoginBox);
window.addEventListener("load", centerLoginBox);
});
function centerLoginBox() {
if (window.orientation == 90 || window.orientation == -90) { //Landscape Mode
$('#loginbox').css('margin-top', '20%');
alert(window.orientation);
}
else if (window.orientation == 0 || window.orientation == 180) { //Portrait Mode
$('#loginbox').css('margin-top', '40%');
alert(window.orientation);
}
在第二个选项卡中,警报在iPad中对竖屏模式会抛出'90'和'-90'的值,而对横屏模式则是'0'和'180'的值(与此相反的行为)。这是否是iOS和Android之间的设计差异?有什么通用解决方案可以解决这个问题吗?