zoukankan      html  css  js  c++  java
  • 如果js设置移动端有两种方式 大家可以参考

    //使用em单位
    		var scaleObj = {
    			documentEle : document.documentElement,
    			deviceWidth : document.documentElement.clientWidth,
    			scale : 0,
    			resetPage :  function(){
    				this.scale = this.deviceWidth/6.4;
    				this.documentEle.style.fontSize = this.scale + 'px';
    			},
    			init :function(falseCode){
    				this.ChangeDevW();
    				this.deviceWidth < 640 ? this.resetPage() : falseCode;
    			},
    			ChangeDevW : function(){
    				this.deviceWidth = this.documentEle.clientWidth;
    			}
    		};
    		window.onload = function(){
    			scaleObj.init(false);
    		}
    		window.onresize = function(){
    			scaleObj.init(scaleObj.documentEle.style.fontSize = 625 + '%');
    		};
    		
    		//使用px单位
    		var vieWport = {
    			phoneWidth : parseInt(window.screen.width),
    			phoneScale : this.phoneWidth / 640,
    			ua : navigator.userAgent,
    			init : function(){
    				 	if (/Android (d+.d+)/.test(this.ua)) {
    			        var version = parseFloat(RegExp.$1);
    			        if (version > 2.3) {
    			            document.write('<meta name="viewport" content="width=640, initial-scale= ' + this.phoneScale + ' ,minimum-scale = ' + this.phoneScale + ', maximum-scale = ' + this.phoneScale + ', target-densitydpi=device-dpi">')
    			        } else {
    			            document.write('<meta name="viewport" content="width=640, initial-scale= ' + this.phoneScale + ' , target-densitydpi=device-dpi">')
    			        }
    			    } else {
    			        document.write('<meta name="viewport" content="width=640, user-scalable=no, target-densitydpi=device-dpi">')
    			    }
    			 }
    		}
    
    		vieWport.init();
    

      

  • 相关阅读:
    C语言第三次博客作业单层循环结构
    C语言字符数组
    C语言第一次作业
    C语言作业函数
    C语言嵌套循环
    C语言第二次作业分支结构
    C语言作业数组
    1712新生素拓活动总结
    C语言第0次作业
    C语言作业数据类型
  • 原文地址:https://www.cnblogs.com/rainheader/p/4738793.html
Copyright © 2011-2022 走看看