使用maximum-scale
和minimum-scale
停止变焦别因为那样你就会失去用户放大的能力。这的确是一个糟糕的主意,因为它使您的用户眼睛不好生气,你的网站不放大,而其他网站做...
我尝试超时和各种花式的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);
这是一个SOLUT离子很好地包裹在一个IIFE,所以你不必担心名称空间问题。
只需将它放入您的脚本(如果您使用jQuery,则不会进入document.ready()
)和中提琴!
它所做的只是在devicemotion
上禁用缩放,表明orientationchange
即将发生。这是我见过的最好的解决方案,因为它实际上工作并且不禁用缩放。
编辑:这种方法并不总是可靠的,特别是当你拿着一个角度的ipad。此外,我不认为这个事件可用于第一代ipad
我只是进行了一些初步的测试和以下为我创造了奇迹:'' – Bitmanic
初始缩放比例对我也有帮助 - on iPad。 – cbuck12000
这是一个很好的解决方法,我觉得是移动Safari浏览器中的一个错误。钳的原始元标记是我通常如何设置我的网站。我怀疑Safari中的某些东西在某些网站中的行为并不像预期的那样混乱,最终导致此问题。 – ghostfly