zoukankan      html  css  js  c++  java
  • 『REM』手机屏幕适配

    function adapt(designWidth, rem2px){
    
      var d = window.document.createElement('div');
    
      d.style.width = '1rem';
    
      d.style.display = "none";
    
      var head = window.document.getElementsByTagName('head')[0];
    
      head.appendChild(d);
    
      var defaultFontSize = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width'));
    
      d.remove();
    
      document.documentElement.style.fontSize = window.innerWidth / designWidth * rem2px / defaultFontSize * 100 + '%';
    
      var st = document.createElement('style');
    
      var portrait = "@media screen and (min- "+window.innerWidth+"px) {html{font-size:"+((window.innerWidth/(designWidth/rem2px)/defaultFontSize)*100) +"%;}}";
    
      var landscape = "@media screen and (min- "+window.innerHeight+"px) {html{font-size:"+((window.innerHeight/(designWidth/rem2px)/defaultFontSize)*100) +"%;}}"
    
      st.innerHTML = portrait + landscape;
    
      head.appendChild(st);
    
      return defaultFontSize
    
    };
    
    var defaultFontSize = adapt(640, 100);
    

      转载地址:http://mp.weixin.qq.com/s/JIRN56acxvJgmzk1Fjj6LA

  • 相关阅读:
    .net的25个小技巧
    使用ASP.Net2.0国际化你的网站祥解
    国外C#开源项目(转)
    千千阙歌
    js中var的有或无重复声明和以后的声明
    XMLHttpRequest
    java参数与引用
    Total Commander
    XMLDOM 的async属性
    Java内嵌类
  • 原文地址:https://www.cnblogs.com/zhoubingyan/p/8677758.html
Copyright © 2011-2022 走看看