-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ | |
"Dispatcher", | ||
"dotCase", | ||
"download", | ||
"dpr", | ||
"durationFormat", | ||
"each", | ||
"easing", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<require>dpr</require> | ||
<script> | ||
console.log(dpr.get()); | ||
dpr.on('change', dpr => console.log(dpr)); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## CN | ||
|
||
设备像素比工具库。 | ||
|
||
### on | ||
|
||
绑定 change 事件。 | ||
|
||
### off | ||
|
||
解绑 change 事件。 | ||
|
||
### get | ||
|
||
获取当前设备像素比。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Device pixel ratio helper. | ||
* | ||
* ### on | ||
* | ||
* Bind change event. | ||
* | ||
* ### off | ||
* | ||
* Unbind change event. | ||
* | ||
* ### get | ||
* | ||
* Get current device pixel ratio. | ||
*/ | ||
|
||
/* example | ||
* dpr.on('change', function(dpr) { | ||
* console.log(dpr); // -> 2 | ||
* }); | ||
* dpr.get(); // -> 1 | ||
*/ | ||
|
||
/* module | ||
* env: browser | ||
*/ | ||
|
||
/* typescript | ||
* export declare namespace dpr { | ||
* interface IDpr extends Emitter { | ||
* get(): number; | ||
* } | ||
* } | ||
* export declare const dpr: dpr.IDpr; | ||
*/ | ||
|
||
_('Emitter MediaQuery'); | ||
|
||
const m = new MediaQuery(`(resolution: ${get()}dppx)`); | ||
|
||
exports = { | ||
get | ||
}; | ||
|
||
Emitter.mixin(exports); | ||
|
||
function get() { | ||
return window.devicePixelRatio || 1; | ||
} | ||
|
||
function change() { | ||
const dpr = get(); | ||
m.setQuery(`(resolution: ${dpr}dppx)`); | ||
exports.emit('change', dpr); | ||
} | ||
|
||
m.on('match', change); | ||
m.on('unmatch', change); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
expect(dpr.get()).to.equal(window.devicePixelRatio); |