iPad (Safariブラウザ)とSamsung Tab 2 (デフォルトブラウザ)でWebアプリケーションをテストしています。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);
}
タブ2では、アラートは横向きモードの場合は「0」と「180」をスローし、縦向きモードの場合は値「90」と「-90」をスローします(iPadでは逆の動作です)。
これはiOSとAndroidのデザインの違いですか?この問題の一般的な解決策は何でしょうか?