Neutral Point Measurement
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    to-pxpublic

    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('em'))
    console.log(toPX('vh'))
    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 unit.

    • unit is a CSS unit type
    • element is an optional element in which the unit is computed (default is document.body)

    Returns The number of pixels in one unit

    Note Conversions for % are not supported since they are context dependent.

    License

    (c) 2015 Mikola Lysenko. MIT License

    install

    npm i to-px

    Downloadsweekly downloads

    12,929

    version

    1.0.1

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar