<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
var phoneWidth = parseInt(window.screen.width);
var phoneScale = phoneWidth/640;
var ua = navigator.userAgent;
if (/Android (\d+\.\d+)/.test(ua)){
var version = parseFloat(RegExp.$1);
if(version>2.3){
document.write('<meta name="viewport" content="width=640, minimum-scale = '+phoneScale+', maximum-scale = '+phoneScale+', target-densitydpi=device-dpi">');
}else{
document.write('<meta name="viewport" content="width=640, target-densitydpi=device-dpi">');
}
} else {
document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">');
}
可以参考 **手淘** 的 [flexible.js](https:
**腾讯方案**
var autoScale = function(){
var ratio = 320/504,
winW = document.getElement.clientWidth,
winH = document.getElement.clientHeight,
ratio2 = winW/winH,
scale;
if(ratio<ratio2){
scale = (winH/504).toString().substring(0, 6);
}else{
scale = (winW/320).toString().substring(0, 6);
}
var cssText = '-webkit-transform: scale('+scale+');-webkit-transform-origin: top; opacity:1;'
$('.wrap').attr('style', cssText);
}
setTimeout(function(){
if(document.documentElement.clientWidth/document.documentElement.clientHeight !== 320/504){
autoScale();
}else{
$('.page').css({'opacity': 1});
}
}, 300);
window.addEventListener('onorientationchange' in window?'orientationchange':'resize', autoScale, false){
detectOrientatioin();
}
function detectOrientatioin(){
if(window.orientation==180 || window.orientation==0){
}
if(window.orientation==90 || window.orientation==-90){
}
}