2012-08-01 77 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); 

};