0

因此,我使用 phoneGap/Cordova 和 Jquery mobile 为 iPad 设计了这个应用程序。

在研究了如何在方向变化时更改图像并浏览 Stack Overflow 的史诗资源之后。我实现了这段代码。

// 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>

谁能说我做错了什么,这可能是愚蠢的,但我看不到。任何帮助将不胜感激。

4

1 回答 1

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);

};
于 2012-08-01T17:40:41.793 回答