-
-
Save plilion/b37b17efb5074c456afe to your computer and use it in GitHub Desktop.
自适应
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //屏幕 适配 | |
| 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