项目作者: yugasun

项目描述 :
Self adaption plugin for mobile development.
高级语言: CSS
项目地址: git://github.com/yugasun/px2rem.scss.git
创建时间: 2017-11-07T06:59:40Z
项目社区:https://github.com/yugasun/px2rem.scss

开源协议:MIT License

下载


px2rem.scss

Downloads
Version

Self adaption plugin for mobile development.

Install

  1. npm install px2rem.scss --save

Usage

  1. In html <head> tag, add viewport and designBaseWidth,as below:
  1. <head>
  2. <meta charset="utf-8">
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  4. <title>demo</title>
  5. <script>
  6. var designBaseWidth = 375
  7. </script>
  8. </head>
  1. import px2rem.config.min.js file,
  1. <head>
  2. <meta charset="utf-8">
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  4. <title>demo</title>
  5. <script>
  6. var designBaseWidth = 375
  7. </script>
  8. <script src="https://unpkg.com/px2rem.scss"></script>
  9. </head>

Notice: this plugin need calculate the html tag base font-size before dom rendering, otherwise web page will initial depend on font-size:16px to calculate rem value, this will cause page to rerender and repain.

  1. Before you use mixins in px2rem.scss, plz import firstly:
  1. @import 'path/to/px2rem.scss';
  2. html {
  3. @include font-dpr(16px);
  4. @include px2rem(width, 320px);
  5. }

Remarks

px2rem.scss provide two sass mixin

  1. font-dpr - calculate font size
  2. px2rem - convert px to rem

Notice:The default base font size is 16px for html.

License

MIT