// $(function(){ // /*750代表设计师给的设计稿的宽度,你的设计稿是多少,就写多少;100代表换算比例,这里写100是为了以后好算,比如,你测量的一个宽度是100px,就可以写为1rem,以及1px=0.01rem等等*/ // }) // function getRem(pwidth, prem) { // var html = document.getElementsByTagName("html")[0]; // var oWidth = document.body.clientWidth || document.documentElement.clientWidth; // var oWindowWidth = document.body.clientWidth;//判断如果是手机登录则调用 fontSize函数 // if (oWindowWidth <= 768) { // html.style.fontSize = oWidth / pwidth * prem + "px"; // } else { // $("html").css("fontSize", ""); // } // } // $(window).resize(function(){ // getRem(750, 100) // }) // getRem(750, 100) function sm(){ //获取html元素 var psd = 750; var html = document.getElementsByTagName('html')[0]; //屏幕的宽度(兼容处理) var w = document.documentElement.clientWidth || document.body.clientWidth; //750这个数字是根据你的设计图的实际大小来的,所以值具体根据设计图的大小 html.style.fontSize = w / psd * 100+ "px"; } /*手机版判断*/ if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) { //手机 sm(); $(window).resize(function(){ sm(); }) } else { //电脑 $("html").css("fontSize",""); } /*屏幕小于768*/ if($(window).width()<750){ sm(); }else{ $("html").css("fontSize",""); } $(window).resize(function(){ if($(window).width()<750){ sm(); }else{ $("html").css("fontSize",""); } })