iPadが横向きモードの場合は、divを追加したいと思います。これを見つけることができるある種のifステートメントはありますか?
ありがとう
iPadが横向きモードの場合は、divを追加したいと思います。これを見つけることができるある種のifステートメントはありますか?
ありがとう
jQTouchは次のようにチェックします。
orientation = Math.abs(window.orientation) == 90 ? 'landscape' : 'portrait';
http://github.com/senchalabs/jQTouch/blob/master/jqtouch/jqtouch.js
onorientationchangeイベントを聞くこともできます
前の回答を参照してください:JavaScriptを使用してブラウザでAndroid携帯の回転を検出する
ドキュメントの幅を簡単にチェックできます。
$(window).width();
変数に設定してから、iPadのネイティブ解像度(縦向きで768px x 1024px)に対して変数を確認できます。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rotation Test</title>
<link type="text/css" href="css/style.css" rel="stylesheet"></style>
<script src="js/jquery-1.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
window.addEventListener("resize", function() {
// Get screen size (inner/outerWidth, inner/outerHeight)
var height = $(window).height();
var width = $(window).width();
if(width>height) {
// Landscape
$("#mode").text("LANDSCAPE");
} else {
// Portrait
$("#mode").text("PORTRAIT");
}
}, false);
</script>
</head>
<body onorientationchange="updateOrientation();">
<div id="mode">LANDSCAPE</div>
</body>
</html>
すべてのブラウザと互換性のあるソリューションを試すことができます。
以下はorientationchange
互換性の写真です:
したがって、私は
orientaionchange
ポリフィルを作成します。これは、orientationchangeユーティリティライブラリを修正するための@media属性に基づいています-<a href = "https://github.com/zhansingsong/orientationchange-fix" rel = "nofollow noreferrer">orientationchange-修正
window.addEventListener('orientationchange', function(){
if(window.neworientation.current === 'portrait|landscape'){
// do something……
} else {
// do something……
}
}, false);
次に、によって現在の方向の状態を取得し、によってwindow.neworientation.current
初期の方向の状態を取得できますwindow.neworientation.init
。