Jquery mobile orientation在横向模式下启动时发生更改错误



我有某种应用程序,其中的界面取决于方向的变化。所以我有两个接口portraitSet()landscapeSet()的函数。以下是我如何赶上方向改变事件的代码:

$(window).on("orientationchange",function(event){
    alert(event.orientation);
        if (event.orientation == 'portrait')
        {
            $(portraitSet());
        }
        else if (event.orientation == 'landscape')
        {
            $(landscapeSet());
        }
});

在人像模式下启动应用程序时,它工作得很好,但当在横向模式下启动该应用程序并试图将手机设置为人像模式时,我的alert(event.orientation)会给我消息"横向",但手机处于人像模式。我的错误在哪里?

hi使用此代码。。。。。

$(window).resize( function(){
    var height = $(window).height();
    var width = $(window).width();
        if(width>height) {
      // Landscape
          alert("LANDSCAPE");
        } else {
      // Portrait
        alert("PORTRAIT");
        }
       });

如果您需要更多信息,请参阅