||

js手机横竖屏判断

在ipad/iphone开发中我们往往需要判断用户目前的屏幕的位置,这样加以优化显示应用内容。今天这里我们分享一个jQuery的代码,能够有效帮助大家判断横屏或者竖屏。注意这里调用了jQuery的方法,所以你需要引用jQuery类库。

title

function orient() {
alert(‘gete’);
if (window.orientation == 0 || window.orientation == 180) {
$(“body”).attr(“class”, “portrait”);
orientation = ‘portrait’;
return false;
}
else if (window.orientation == 90 || window.orientation == -90) {
$(“body”).attr(“class”, “landscape”);
orientation = ‘landscape’;

return false;
}
}

$(function(){
orient();
});

$(window).bind( ‘orientationchange’, function(e){
orient();
});

类似文章