From 8bc18d3d37a688f792262b2694c8fd1edf0428fe Mon Sep 17 00:00:00 2001 From: Jone Casper Date: Tue, 17 Nov 2015 08:52:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E4=B8=8D=E4=BD=BF=E7=94=A8fl?= =?UTF-8?q?exible=E4=BC=98=E5=8C=96=E6=96=B9=E6=A1=88=E7=9A=84=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=85=BC=E5=AE=B9=E5=B1=8F=E5=B9=95=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对于不使用flexible优化方案的手机,应该设置with=device-with,使其宽度符合物理宽度 --- src/flexible.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/flexible.js b/src/flexible.js index 4e7c545..18cf752 100644 --- a/src/flexible.js +++ b/src/flexible.js @@ -31,9 +31,10 @@ } } + var isAndroid = win.navigator.appVersion.match(/android/gi); + var isIPhone = win.navigator.appVersion.match(/iphone/gi); + if (!dpr && !scale) { - var isAndroid = win.navigator.appVersion.match(/android/gi); - var isIPhone = win.navigator.appVersion.match(/iphone/gi); var devicePixelRatio = win.devicePixelRatio; if (isIPhone) { // iOS下,对于2和3的屏,用2倍的方案,其余的用1倍方案 @@ -55,7 +56,9 @@ if (!metaEl) { metaEl = doc.createElement('meta'); metaEl.setAttribute('name', 'viewport'); - metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no'); + metaEl.setAttribute('content', + isAndroid ? 'width=device-width, ' : '' + + 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no'); if (docEl.firstElementChild) { docEl.firstElementChild.appendChild(metaEl); } else { @@ -114,4 +117,4 @@ return val; } -})(window, window['lib'] || (window['lib'] = {})); \ No newline at end of file +})(window, window['lib'] || (window['lib'] = {}));