Skip to content

Commit

Permalink
mresize方法增加一个回调函数,优化dpr为整数
Browse files Browse the repository at this point in the history
  • Loading branch information
imochen committed Mar 3, 2016
1 parent b869d65 commit 99e9fe4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ body{
```javascript
hotcss.mresize();
```
#### hotcss.callback
触发mresize的时候会执行该方法。
```javascript
hotcss.callback = function(){
//your code here
}
```


#### 单位转换hotcss.px2rem/hotcss.rem2px
`hotcss.px2rem``hotcss.rem2px`。<del>你可以预先设定`hotcss.designWidth`</del>可以在meta中设置`design-width`,则之后使用这两个方法不需要再传递第二个参数。

Expand Down
4 changes: 4 additions & 0 deletions example/hotcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
maxWidth = 540,
designWidth = 0;

dpr = dpr >= 3 ? 3 : ( dpr >=2 ? 2 : 1 );

//允许通过自定义name为hotcss的meta头,通过initial-dpr来强制定义页面缩放
if (hotcssEl) {
var hotcssCon = hotcssEl.getAttribute('content');
Expand Down Expand Up @@ -90,6 +92,8 @@

document.documentElement.style.fontSize = ( innerWidth*20/320 ) + 'px';

hotcss.callback && hotcss.callback();

};

hotcss.mresize();
Expand Down
4 changes: 4 additions & 0 deletions src/hotcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
maxWidth = 540,
designWidth = 0;

dpr = dpr >= 3 ? 3 : ( dpr >=2 ? 2 : 1 );

//允许通过自定义name为hotcss的meta头,通过initial-dpr来强制定义页面缩放
if (hotcssEl) {
var hotcssCon = hotcssEl.getAttribute('content');
Expand Down Expand Up @@ -90,6 +92,8 @@

document.documentElement.style.fontSize = ( innerWidth*20/320 ) + 'px';

hotcss.callback && hotcss.callback();

};

hotcss.mresize();
Expand Down

0 comments on commit 99e9fe4

Please sign in to comment.