├── .editorconfig
├── .gitignore
├── README.md
├── index.js
├── index.min.js
└── package.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 |
3 | root = true
4 |
5 | [*]
6 | charset = utf-8
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 | max_line_length = off
11 | indent_style = space
12 | indent_size = 2
13 |
14 | [{package.json,.travis.yml,.eslintrc*}]
15 | indent_style = space
16 | indent_size = 2
17 |
18 | [*.md]
19 | max_line_length = off
20 | trim_trailing_whitespace = false
21 |
22 | [COMMIT_EDITMSG]
23 | max_line_length = off
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OS
2 | .DS_Store
3 | Thumbs.db
4 | Desktop.ini
5 |
6 | # IDE
7 | .idea/
8 | .vscode/
9 | .project
10 | *.swp
11 | *.swo
12 |
13 | # Dependency, Cache, Temporary
14 | node_modules/
15 | bower_components/
16 | .svn/
17 | .sass-cache/
18 | .nodejs-cache/
19 | npm-debug.log
20 |
21 | # Distribution
22 | coverage/
23 | dist/
24 | docs/
25 | *.iml
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # amfe-flexible
2 |
3 | [Classic edition (0.3.2)](https://github.com/amfe/lib-flexible/tree/master)
4 |
5 | > 由于`viewport`单位得到众多浏览器的兼容,`lib-flexible`这个过渡方案已经可以放弃使用,不管是现在的版本还是以前的版本,都存有一定的问题。建议大家开始使用`viewport`来替代此方。
6 | ## Usage
7 |
8 | #### Install
9 |
10 | `npm i -S amfe-flexible`
11 |
12 | #### Import
13 |
14 | ```html
15 |
16 |
17 | ```
18 |
19 | You can inline this file with [inline-source](https://npmjs.org/package/inline-source).
20 |
21 | #### Develop
22 |
23 | Use [postcss-adaptive](https://www.npmjs.com/package/postcss-adaptive).
24 |
25 | ## License
26 |
27 | (The MIT License)
28 |
29 | Copyright (c) 2016 Alibaba MFE
30 |
31 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
32 |
33 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
34 |
35 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | (function flexible (window, document) {
2 | var docEl = document.documentElement
3 | var dpr = window.devicePixelRatio || 1
4 |
5 | // adjust body font size
6 | function setBodyFontSize () {
7 | if (document.body) {
8 | document.body.style.fontSize = (12 * dpr) + 'px'
9 | }
10 | else {
11 | document.addEventListener('DOMContentLoaded', setBodyFontSize)
12 | }
13 | }
14 | setBodyFontSize();
15 |
16 | // set 1rem = viewWidth / 10
17 | function setRemUnit () {
18 | var rem = docEl.clientWidth / 10
19 | docEl.style.fontSize = rem + 'px'
20 | }
21 |
22 | setRemUnit()
23 |
24 | // reset rem unit on page resize
25 | window.addEventListener('resize', setRemUnit)
26 | window.addEventListener('pageshow', function (e) {
27 | if (e.persisted) {
28 | setRemUnit()
29 | }
30 | })
31 |
32 | // detect 0.5px supports
33 | if (dpr >= 2) {
34 | var fakeBody = document.createElement('body')
35 | var testElement = document.createElement('div')
36 | testElement.style.border = '.5px solid transparent'
37 | fakeBody.appendChild(testElement)
38 | docEl.appendChild(fakeBody)
39 | if (testElement.offsetHeight === 1) {
40 | docEl.classList.add('hairlines')
41 | }
42 | docEl.removeChild(fakeBody)
43 | }
44 | }(window, document))
45 |
--------------------------------------------------------------------------------
/index.min.js:
--------------------------------------------------------------------------------
1 | !function(e,t){function n(){t.body?t.body.style.fontSize=12*o+"px":t.addEventListener("DOMContentLoaded",n)}function d(){var e=i.clientWidth/10;i.style.fontSize=e+"px"}var i=t.documentElement,o=e.devicePixelRatio||1;if(n(),d(),e.addEventListener("resize",d),e.addEventListener("pageshow",function(e){e.persisted&&d()}),o>=2){var a=t.createElement("body"),s=t.createElement("div");s.style.border=".5px solid transparent",a.appendChild(s),i.appendChild(a),1===s.offsetHeight&&i.classList.add("hairlines"),i.removeChild(a)}}(window,document);
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "amfe-flexible",
3 | "version": "2.2.1",
4 | "description": "Build flexible page on mobile platform",
5 | "keywords": [
6 | "lib",
7 | "amfe",
8 | "flexible",
9 | "mobile",
10 | "css",
11 | "rem",
12 | "vw"
13 | ],
14 | "homepage": "https://github.com/amfe/lib-flexible",
15 | "repository": {
16 | "type": "git",
17 | "url": "git@github.com:amfe/lib-flexible.git"
18 | },
19 | "author": [
20 | {
21 | "name": "mingelz",
22 | "email": "mingelz@gmail.com"
23 | }
24 | ],
25 | "scripts": {
26 | "compress": "uglifyjs index.js -o index.min.js -c -m"
27 | },
28 | "dependencies": {},
29 | "devDependencies": {
30 | "uglify-js": "^3.0.27"
31 | },
32 | "license": "MIT"
33 | }
34 |
--------------------------------------------------------------------------------