jquery mobile orientation detection

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 06:37:06

问题


I am using jquery-mobile and it seems it doesn't detect the landscape setting. What I am using:

iphone simulator Version 4.3 (238.2) from Xcode Version 4.1 Build 4B110 jquery mobile

I tried to do this in my mobile.js

$(window).bind('orientationchange resize', function(event){
  alert(event.orientation)
})

and turning the simulator around just keeps giving me an alert that says "portrait" when it clearly should be landscape.

am i doing something wrong here? I also tried using media queries in our jammit call:

<%= include_stylesheet :landscape, :media => "all and (orientation: landscape)" %>

but to no avail. AM i doing something wrong here?

The main bug btw is that even when turning the iphone, the display still stays at portrait width for us.


回答1:


I found this in the jQM b2 js file:

  • http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.js

JS:

alert('Orientation: ' + jQuery.event.special.orientationchange.orientation());

Here is the function itself:

// Get the current page orientation. This method is exposed publicly, should it
// be needed, as jQuery.event.special.orientationchange.orientation()
$.event.special.orientationchange.orientation = get_orientation = function() {
    var elem = document.documentElement;
    return elem && elem.clientWidth / elem.clientHeight < 1.1 ? "portrait" : "landscape";
};


来源:https://stackoverflow.com/questions/7003533/jquery-mobile-orientation-detection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!