2012年7月31日 星期二

透過JQuery判斷手持裝置直向、橫向

var checkOrientation = function(){

        mode = Math.abs(window.orientation) == 90 ? 'landscape' : 'portrait';

        // 在 Android 上使用 Opera Mobile 測試, 發現要另外這樣判斷
        if ( $.browser.opera )
        {
            width = screen.width;
            height = screen.height;
            mode = width > height ? "landscape" : "portrait";
        }

        // 本例為希望在使用者用橫向瀏覽時,就秀出遮罩或警示訊息
        if (mode == 'landscape')
        {
           // 警語遮罩 顯示
           alert(''landscape')');
        } else {
           // 警語遮罩 關閉
           alert('"portrait";');
        }
};

window.addEventListener("resize", checkOrientation, false);
window.addEventListener("orientationchange", checkOrientation, false);
setInterval(checkOrientation, 500);



原始介紹文章出自於此



沒有留言:

張貼留言