对此使用元标记不起作用。我试过元标记和orientationchange
和gesturechange
事件可能的每个组合,我想超时和各种花式的javascript的,后来我发现这一点: https://github.com/scottjehl/iOS-Orientationchange-Fix
通过此相关的问题:How do I reset the scale/zoom of a web app on an orientation change on the iPhone?
在该职位安德鲁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很好地包裹着,所以你不必担心名称空间问题的解决方案。
只需将它放入您的脚本(如果您使用jQuery,则不会进入document.ready()
)和中提琴!
它所做的只是在devicemotion
上禁用缩放,表明orientationchange
即将发生。这是我见过的最好的解决方案,因为它实际上工作并且不禁用缩放。
编辑:这种方法并不总是可靠的,特别是当你拿着一个角度的ipad。另外,我不认为这个事件可用于第1代iPad
完全禁用缩放并不是一个好主意..请参阅Scott Jehl的解决方案:https://github.com/scottjehl/iOS-Orientationchange-Fix/blob/master /ios-orientationchange-fix.js – tmsimont 2012-06-01 22:10:24