移动端公共方法封装

//公共参数公共方法;
var commonObj={
    version:‘‘,
    design_width:750,
    downUrl: "",
    system:(navigator.userAgent).match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)?"ios":"android",
   testApi:{
         
    },
    onlineApi:{
        
    },
   serviceTypeFn: function() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["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;
    },
    urlParmFn: function(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var urlTmp = decodeURI(window.location.search)
        var r = urlTmp.substr(1).match(reg);
        if(r != null) return unescape(r[2]);
        return null;
    },
   remFn: function() {
        if(this.IsPC()) {
            this.view_width = document.documentElement.clientWidth > this.design_width ? this.design_width : document.documentElement.clientWidth;
            this.body.className = ‘pc‘;
        } else {
            this.view_width = document.documentElement.clientWidth < 320 ? 320 : document.documentElement.clientWidth;
        }
        this.body.style.opacity = 1;
        this.body.style.fontSize = this.view_width * 100 / this.design_width + ‘px‘;
        if(window.location.href.indexOf("testh5.hotyq.com")!=-1 || window.location.href.indexOf("www.hotyq.com")!=-1){
           for(name in change.testApi){
                change[name]=change.testApi[name]
           }
        }else{
            for(name in change.proApi){
                change[name]=change.proApi[name]
           }
        }
    },
}
change.action();
window.addEventListener(‘resize‘, function() {
    change.action();
})

 

移动端公共方法封装

上一篇:技术|Android安装包极限优化


下一篇:arcpy自动制图实战(arcpy.mapping迁移至arcpy.mp)(转)