旋转iPad上的JavaScript自动缩放

时间:2012-09-17 14:47:11

标签: html ipad mobile-safari viewport screen-orientation

我的页面在横向模式下工作正常但在纵向模式下我需要缩小一点然后它适合屏幕。所以我想编写一个JavaScript,当我以纵向模式旋转时缩小或缩小我的页面

if(navigator.platform == 'iPad') {
        window.onorientationchange = function () {
            var orientation = window.orientation;
            // Look at the value of window.orientation:
            if (orientation === 0) {
                alert("iPad is in Portrait mode.");
                 // my code goes here 
                var viewportmeta = document.querySelector('meta[name="viewport"]');
                viewportmeta.content = 'width = 1003,initial-scale = 0.5, maximum-scale = 2.0, minimum-scale=0.7';

            }
            else if (orientation === 90) {
                // iPad is in Landscape mode. The screen is turned to the left.
            }
            else if (orientation === -90) {
                // iPad is in Landscape mode. The screen is turned to the right.
            }
        }

    }

scale = 0.5;

中看起来很好

1 个答案:

答案 0 :(得分:0)

我刚用<meta name="viewport" content="width=640"> 并且每一个都解决了