js 橫屏 豎屏 判斷

    //屏幕方向標識,0橫屏,其餘值豎屏
    var orientation=0;
    //轉屏事件,內部功能能夠自定義
    function screenOrientationEvent(){
        if(orientation == 0)document.getElementById("change").value="豎";
        else document.getElementById("change").value="橫";
    }
    var innerWidthTmp = window.innerWidth;
    //橫豎屏事件監聽方法
    function screenOrientationListener(){
        try{
            var iw = window.innerWidth;
            //屏幕方向改變處理
            if(iw != innerWidthTmp){
                if(iw>window.innerHeight)orientation = 90;
                else orientation = 0;
                //調用轉屏事件
//                    screenOrientationEvent();

                if(orientation == 0) {
                    console.log( "豎");
                    gaodu();
                }else{
                    console.log( "橫");
                   gaodu();
                }
                innerWidthTmp = iw;
            }
        } catch(e){alert(e);};
        //間隔固定事件檢查是否轉屏,默認10毫秒
        setTimeout("screenOrientationListener()",100);
    }
    //啓動橫豎屏事件監聽
    screenOrientationListener();
相關文章
相關標籤/搜索