Nis*_*ant 23 jquery jquery-mobile cordova
有人可以让我知道jquery mobile在电话差距中的方向更改事件的正确代码吗?我在哪里以及如何实现此orientationChange函数?
gho*_*der 45
$(window).bind('orientationchange', _orientationHandler);
Run Code Online (Sandbox Code Playgroud)
然后在_orientationHandler
函数中,有类似的东西:
if(event.orientation){
if(event.orientation == 'portrait'){
//do something
}
else if(event.orientation == 'landscape') {
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
$(window).bind( 'orientationchange', function(e){
if ($.event.special.orientationchange.orientation() == "portrait") {
//Do whatever in portrait mode
} else {
//Do Whatever in landscape mode
}
});
Run Code Online (Sandbox Code Playgroud)
如果您的目标是iOS并且orientationchange不起作用,您可以在bind函数的event参数中添加resize事件.由于更改方向也会触发调整大小事件.