iPad layout scales up when rotating from portrait to landscape

前端 未结 11 1455
萌比男神i
萌比男神i 2020-12-02 04:32

I have a added to the \"viewport\" meta tag \"width=device-width,initial-scale=1.0\" and on an iPad the page loads up fine in landscape mode, the i

11条回答
  •  感动是毒
    2020-12-02 05:12

    ------ Update ------

    This is not an issue anymore in iOS7. And there is better fix by Scott Jehl on github scottjehl/iOS-Orientationchange-Fix that works for iOS6.

    ------ Original answer ------

    Jeremy Keith (@adactio) has a good solution for this on his blog Orientation and scale

    Keep the Markup scalable

    
    

    Then disable scalability with javascript until gesturestart with this script:

    if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
        var viewportmeta = document.querySelector('meta[name="viewport"]');
        if (viewportmeta) {
            viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
            document.body.addEventListener('gesturestart', function () {
                viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
            }, false);
        }
    }
    

提交回复
热议问题