为此使用元标记不起作用。我已经尝试了所有可能的元标记和事件组合orientationchange
,gesturechange
我尝试了超时和各种花哨的 javascript,然后我发现了这个:
https ://github.com/scottjehl/iOS-Orientationchange-Fix
通过这个相关问题:如何在 iPhone 上更改方向时重置 Web 应用程序的缩放/缩放?
在那篇文章中,Andrew Ashbacher 发布了一个指向 Scott Jehl 编写的代码的链接:
/*! A fix for the iOS orientationchange zoom bug. Script by @scottjehl, rebound by @wilto.MIT License.*/(function(m){if(!(/iPhone|iPad|iPod/.test(navigator.platform)&&navigator.userAgent.indexOf("AppleWebKit")>-1)){return}var l=m.document;if(!l.querySelector){return}var n=l.querySelector("meta[name=viewport]"),a=n&&n.getAttribute("content"),k=a+",maximum-scale=1",d=a+",maximum-scale=10",g=true,j,i,h,c;if(!n){return}function f(){n.setAttribute("content",d);g=true}function b(){n.setAttribute("content",k);g=false}function e(o){c=o.accelerationIncludingGravity;j=Math.abs(c.x);i=Math.abs(c.y);h=Math.abs(c.z);if(!m.orientation&&(j>7||((h>6&&i<8||h<8&&i>6)&&j>5))){if(g){b()}}else{if(!g){f()}}}m.addEventListener("orientationchange",f,false);m.addEventListener("devicemotion",e,false)})(this);
这是一个很好地包装在IIFE中的解决方案,因此您不必担心名称空间问题。
只需将其放入您的脚本(document.ready()
如果您使用 jQuery,则不要放入)和中提琴!
它所做的只是禁用对devicemotion
指示orientationchange
即将发生的事件的缩放。这是我见过的最好的解决方案,因为它确实有效并且不会禁用缩放。
编辑:这种方法并不总是可靠的,尤其是当您以一定角度握住 ipad 时。另外,我认为这个活动不适用于第 1 代 ipad