移动端适配,拿走即用

 1 <script>
 2     !function(x){
 3       function w(){
 4         var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;
 5         if(!v&&!u){
 6           var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);
 7           v=x.devicePixelRatio;
 8           tes=x.devicePixelRatio;
 9           v=n?v:1,u=1/v
10         }
11         if(a>=640){
12           r.style.fontSize="40px"
13         }else{
14           if(a<=320){
15             r.style.fontSize="20px"
16           }else{
17             r.style.fontSize=a/320*20+"px"
18           }
19         }
20       }
21       x.addEventListener("resize",function(){w()});
22       w()
23     }(window);
24   </script>
原文地址:https://www.cnblogs.com/rookiehao/p/9153391.html