2012-08-01 95 views
0

所以我設計這個應用程序的iPad使用phoneGap /科爾多瓦和JQuery的移動。改變方向變化的圖像

在研究瞭如何改變方向變化的圖像並瀏覽堆棧溢出的史詩資源之後,我實現了這個代碼。

// The event for orientation change 
var onChanged = function() { 

    // The orientation 
    var orientation = window.orientation, 
     // If landscape, then use "land" otherwise use "port" 
     image = orientation == 90 || orientation == -90 ? "landscape" : "portrait"; 

    // Insert the image 
    $('#introimg').html('<img src="images/appimages/' + image + '-intro-page.png">'); 

}; 

// Bind the orientation change event and bind onLoad 
$(window).bind(orientationEvent, onChanged).bind('load', onChanged); 

我在嘗試更改介紹頁面的圖像。我使用的HTML是:

<div data-role="page" id="intro"> 

     <div data-role="content" class="mycontent" data-theme="a"> 
      <div id="introimg"> 
       <img src="images/appimages/portrait-intro-page.png" alt="" width="768" height="1004" id="imglayer1" /> 
       <br /> 
       <p id="imglayer2"><a href="#help" data-role="button" data-inline="true" data-theme="a">Start designing</a></p> 
      </div> 

     </div> 
    </div> 

任何人都可以說什麼我做錯了,它可能是愚蠢的東西,但我看不到它。任何幫助將不勝感激。

+0

它是否幫助,如果你加括號,如:'圖像=(方向== || 90取向== -90)? 「風景」:「人像」;' – Blazemonger 2012-08-01 13:43:12

+0

不似乎沒有任何區別。 :/ – Bohdi 2012-08-01 13:52:41

回答

0

您可以使用類此:

var onChanged = function() { 

    // The orientation 
    var orientation = (window.orientation == -90 || window.orientation == 90) ? "landscape" : "portrait"; 

    // Insert the image class 
    $("introimg").removeClass("portrait").removeClass("landscape").addClass(orientation); 

};