简体   繁体   English

用于检测“三星银河Android 2.3.5”的方向(横向和纵向模式)的事件

[英]Event to detect orientation (landscape and portrait mode) for “samsung galaxy Android 2.3.5”

I want to show different page design for landscape and portrait mode. 我想为横向和纵向模式显示不同的页面设计。

I want an event which fire every time when user change the mobile from "landscape to portrait" and "portrait to landscape" and page show different design for both the mode. 我希望每次用户将移动设备从“横向改为纵向”和“纵向改为横向”并且页面针对两种模式显示不同的设计时都触发一次事件。

Also in my code each time show the landscape design it is not able to detect the portrait mode.Even when I am running the page in portrait mode. 同样在我的代码中,每次显示横向设计时,它都无法检测到纵向模式,即使我以纵向模式运行页面也是如此。

For following mobile device: 对于以下移动设备:

Device : Samsung Galaxy , 设备 :三星Galaxy,

Os version: Android 2.3.5. 操作系统版本: Android 2.3.5。

In this I am using: 在此我使用:

Jquery mobile version: 1.1.0. jQuery mobile版本: 1.1.0。 ,

Jquery version: 1.7.1 jQuery版本: 1.7.1

My code is running well for "iphone,ipad and htc android mobile" but when I am test this in "Samsung Galaxy" then it is showing landscape page design for both the landscape and portrait mode. 我的代码在“ iphone,ipad和htc android mobile”上运行良好,但是当我在“三星Galaxy”中对其进行测试时,它同时显示了横向和纵向模式的横向页面设计。

My code is: 我的代码是:

 $(document).ready(function () {
    $("#pagecontent.ui-content").css({ 'padding': '0px', 'margin': '0px' });
    checkClientTimeZone();

    position = $.event.special.orientationchange.orientation();
    pagecontentChanges();

    //        $(window).bind("orientationchange", pagecontentChanges);

});
$.event.special.orientationchange.orientation = get_orientation = function () {
    var elem = document.documentElement;
    //alert(elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" :       "landscape");
    return elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" : "landscape";
};
window.addEventListener("orientationchange", function () {
    setTimeout(function () {
        position = $.event.special.orientationchange.orientation();
        pagecontentChanges();
    }, 500);
}, false);
window.addEventListener("resize", function () {
    setTimeout(function () {
        position = $.event.special.orientationchange.orientation();
        pagecontentChanges();
    }, 500);
}, false);


function pagecontentChanges() {

    if (position == "portrait") {
        $("#headertext").css({ "text-align": "center", "margin-top": "-2.6em" });
        $("#login_content").removeClass("landscap_logincontent");
        $("#registerdiv").removeClass("landscap_divwhite");
        $("#tylenol").css({ "width": "100%", "float": "", "margin-right": "0px" });
        $("#button_div .ui-btn").css(" margin-top", ".5em");
        $("#loginbluelink").css("text-align", "center");
        $("#redromantext").css("text-align", "center");
        $('#registerdiv').css({ "float": "" });
        $("#registertext").css({ "margin-top": "0px" });
        $(".divwhite").css({ "width": "60%" });

        $("#loginheader").attr("src", "@img_css_scpt/test_mobile/images/logon_header.png");

    }
    if (position == "landscape") {
        $("#headertext").css({ "text-align": "left", "padding-left": "5%", "margin-top": "1em" });
        $("#login_content").addClass("landscap_logincontent");
        $("#registerdiv").addClass("landscap_divwhite");
        $("#tylenol").css({ "width": "55%", "float": "left", "margin-right": ".5em" });
        $("#button_div .ui-btn").css(" margin-top", "0px");
        $("#loginbluelink").css("text-align", "left");
        $("#redromantext").css("text-align", "left");
        $("#registertext").css({ "margin-top": "5px" });
        $(".divwhite").css({ "width": "71%" });

        $("#loginheader").attr("src", "@img_css_scpt/test_mobile/images/landscap_header_logon.png");
    }
}

Try giving the window.resize event handler a setTimeout : 尝试为window.resize事件处理程序设置setTimeout

$(window).bind("resize", function () {
    setTimeout(function () {
        position = $.event.special.orientationchange.orientation();
        pagecontentChanges();
    }, 500);
});

That's what I did for my own window.resize event handlers for my Droid X that runs Android 2.3.4. 这就是我对运行Android 2.3.4的Droid X的window.resize事件处理程序所做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android和iOS的phonegap应用程序中将所需页面的方向设置为横向和纵向模式下的其他页面 - How to set the orientation for required pages to landscape and other pages in portrait mode in phonegap application for both android and iOS Android平板电脑(三星银河标签)-方向改变时桌子混乱 - Android tablet (Samsung galaxy tab) - table messes up on orientation change 当iPad中方向从横向更改为纵向时,页面会缩小 - Page zooms out when orientation changes from landscape to portrait mode in iPad 使用jQuery以纵向检测iPad - Detect iPad in portrait orientation with jQuery Jquery和HTML5中的纵向和横向模式兼容性 - Portrait and Landscape mode compatibility in Jquery & HTML5 设置方向肖像phonegap android - set orientation portrait phonegap android ipad方向纵向显示电子邮件或触发横向 - ipad orientation portrait to display e message or trigger the Landscape Apple Web App状态栏检测到肖像或风景不起作用 - apple web app status bar detect portrait or landscape not working $(window).width()在iPhone的纵向/横向模式下返回相同的值 - $(window).width() returning same value in portrait/landscape mode of iPhone jQuery移动元素不会从纵向模式重排到横向模式 - JQuery mobile elements not reflowing from portrait to landscape mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM