to-px
Convert any CSS unit to logical pixels ("px")
Last updated 8 years ago by mikolalysenko .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install to-px 
SYNC missed versions from official npm registry.

to-px

Get the scale factor to convert any CSS unit to px (logical pixel units).

testling badge

Example

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

Current Tags

  • 1.1.0                                ...           latest (8 years ago)

3 Versions

  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 15
Today 0
This Week 2
This Month 4
Last Day 2
Last Week 0
Last Month 3
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE