Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/to-px
Convert any CSS unit to logical pixels (aka "px")
https://github.com/mikolalysenko/to-px
Last synced: 5 days ago
JSON representation
Convert any CSS unit to logical pixels (aka "px")
- Host: GitHub
- URL: https://github.com/mikolalysenko/to-px
- Owner: mikolalysenko
- License: mit
- Created: 2015-02-17T21:06:19.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-04-06T02:48:28.000Z (over 4 years ago)
- Last Synced: 2024-12-13T06:04:48.033Z (12 days ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 49
- Watchers: 3
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
to-px
=====
Get the scale factor to convert any CSS unit to `px` (logical pixel units).[![testling badge](https://ci.testling.com/mikolalysenko/to-px.png)](https://ci.testling.com/mikolalysenko/to-px)
# Example
```javascript
var toPX = require('to-px')console.log(toPX('1em'))
console.log(toPX('.23vh'))
console.log(toPX('in'))
```# Install
Note that this module only works within the DOM.
```
npm i to-px
```# API
#### `var scaleFactor = require('to-px')(unit[, element])`
Computes the number of pixels in the `unit` string.
* `unit` is a CSS unit type or a number followed by CSS unit, eg `vh` or `2in`
* `element` is an optional element in which the unit is computed (default is `document.body`)**Returns** The number of pixels in the `unit`
**Note** Conversions for `%` are not supported since they are context dependent.
# License
(c) 2015 Mikola Lysenko. MIT License