5

iPadが横向きモードの場合は、divを追加したいと思います。これを見つけることができるある種のifステートメントはありますか?

ありがとう

4

4 に答える 4

6

jQTouchは次のようにチェックします。

orientation = Math.abs(window.orientation) == 90 ? 'landscape' : 'portrait';

http://github.com/senchalabs/jQTouch/blob/master/jqtouch/jqtouch.js

onorientationchangeイベントを聞くこともできます

前の回答を参照してください:JavaScriptを使用してブラウザでAndroid携帯の回転を検出する

于 2010-08-16T19:31:06.960 に答える
4

ドキュメントの幅を簡単にチェックできます。

$(window).width();

変数に設定してから、iPadのネイティブ解像度(縦向きで768px x 1024px)に対して変数を確認できます。

于 2010-08-16T17:44:32.373 に答える
0
<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>
于 2015-01-08T14:26:54.340 に答える
0

すべてのブラウザと互換性のあるソリューションを試すことができます。

以下は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

于 2016-09-13T09:52:43.247 に答える