适应设备类型的代码封装练习

function IsPC(){

var userAgentInfo = navigator.userAgent;//使用navigator.userAgent来判断浏览器类型。  

var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");  

var flag = true;

    for (var v = 0; v < Agents.length; v++) {

       if (userAgentInfo.indexOf(Agents[v]) >= 0) {

       flag = false;

       break;

       }

    }

   return flag;

}

 

var container = document.getElementById("container");

if(IsPC()) {

container.style.width = "375";

container.style.height = "627";

} else {

container.style.width = document.documentElement.clientWidth || document.body.clientWidth;

container.style.height = document.documentElement.clientHeight || document.body.clientHeight;

}

posted @ 2016-07-30 10:34  夏目友人喵  阅读(145)  评论(0编辑  收藏  举报