问题
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