移动端屏幕尺寸自适应

 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         };

 

posted @ 2015-11-30 17:05  web倩倩  阅读(196)  评论(0编辑  收藏  举报