1. 程式人生 > >判斷手機橫屏和豎屏方向

判斷手機橫屏和豎屏方向


function orient() {
    if (window.orientation == 90 || window.orientation == -90) {
        //ipad、iphone豎屏;Andriod橫屏
        $("body").attr("class", "landscape");
        orientation = 'landscape';
        return false;
    }else if (window.orientation == 0 || window.orientation == 180) {
        //ipad、iphone橫屏;Andriod豎屏
        $("body").attr("class", "portrait");
        orientation = 'portrait';
        return false;
    }
}//使用者變化螢幕方向時呼叫

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