Skip to content

Instantly share code, notes, and snippets.

@plilion
Created June 3, 2015 01:14
Show Gist options
  • Select an option

  • Save plilion/b37b17efb5074c456afe to your computer and use it in GitHub Desktop.

Select an option

Save plilion/b37b17efb5074c456afe to your computer and use it in GitHub Desktop.
自适应
//屏幕 适配
var phoneWidth;
function mobileMeta() {
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">');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment