//window.onload = function(){ // getRem(750,100) //}; //window.onresize = function(){ // getRem(750,100) //}; //function getRem(pwidth,prem){ // var html = document.getElementsByTagName("html")[0]; // var oWidth = document.body.clientWidth || document.documentElement.clientWidth; // html.style.fontSize = oWidth/pwidth*prem + "px"; //} 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",""); } })