移动端屏幕尺寸自适应
1 var metaEl = document.querySelector('meta[name="viewport"]'); 2 var scale; 3 scale = document.documentElement.clientWidth / 320; 4 metaEl.setAttribute("content", "width=320,initial-scale=" + scale + ",maximum-scale=" + scale + ",user-scalable=no"); 5 var ispc = function() { 6 var userAgentInfo = navigator.userAgent; 7 var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"]; 8 var flag = true; 9 for (var v = 0; v < Agents.length; v++) { 10 if (userAgentInfo.indexOf(Agents[v]) > 0) { 11 flag = false; 12 break 13 } 14 } 15 return flag 16 };