// $(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",""); } })