Geen omschrijving

resolution1.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1.  //设计屏幕大小
  2.  var designHeight = 1100;
  3.  var designWidth = 1920;
  4.  /**
  5.   * 插入样式
  6.   * @param {样式} styleStr 
  7.   */
  8.  var initStyle = function(styleStr){
  9.      let uid = 'fontStyle';
  10.      let style = document.getElementById(uid) || document.createElement('style');
  11.      style.id = uid;
  12.      if(style.innerText && style.innerText === styleStr){
  13.          return ;//前后相同,不更新
  14.      }
  15.      style.innerText = styleStr;
  16.      if(!document.getElementById(uid)){
  17.          let head = document.getElementsByTagName('head')[0];
  18.          if(head){
  19.              head.appendChild(style);
  20.          }
  21.      }
  22.  }
  23.  //获得整体比值变化
  24.  var getHeightScale = function(){
  25.      return document.documentElement.clientHeight/ designHeight;
  26.  }
  27. alert(document.documentElement.clientHeight)
  28.  var getWidthScale = function(){
  29.      return document.documentElement.clientWidth / designWidth;
  30.  }
  31.  var getScale = function(){
  32.      return getHeightScale()>=getWidthScale()?getWidthScale():getHeightScale();
  33.  }
  34.  //获得真实字体大小
  35.  var getRealFontSize = function(num){
  36.      return num*getScale();
  37.  }
  38.  //横向
  39.  var getWidthValue = function(num){
  40.      return num*getWidthScale();
  41.  }
  42.  //纵向
  43.  var getHeightValue = function(num){
  44.      return num*getHeightScale();
  45.  }
  46. alert(getHeightValue);
  47.  //所有自适应相关的css都写在下面
  48. var getCss = function(){
  49.     return 
  50. //    .main{
  51. //        padding-bottom:${getHeightValue(30)}px;
  52. //    }
  53. //    .titleCom{
  54. //        font-size:${getRealFontSize(30)}px;
  55. //    }
  56. //    .tabsCom{
  57. //        font-size:${getRealFontSize(18)}px;
  58. //        line-height:${getHeightValue(20)}px;
  59. //    }
  60. //    .tabCom{
  61. //        padding:${getHeightValue(2)}px 0px;
  62. //    }
  63. //    .header_back{
  64. //        height:${getHeightValue(20)}px;
  65. //        padding-left:${getWidthValue(5)}px;
  66. //        line-height:${getHeightValue(18)}px;
  67. //    }
  68. //    .header{
  69. //        height:${getHeightValue(20)}px;
  70. //    }
  71. //    .content_one_item{
  72. //        height:${getHeightValue(170)}px;
  73. //    }
  74. //    .textItem{
  75. //        font-size:${getRealFontSize(22)}px;
  76. //        line-height:${getHeightValue(50)}px;
  77. //        padding-left:${getWidthValue(40)}px;
  78. //    }
  79. //    .textItem img{
  80. //        height:${getHeightValue(20)}px;
  81. //        margin-right:${getWidthValue(5)}px;
  82. //    }
  83. }