1. to-px
Convert any CSS unit to logical pixels ("px")
to-px
Package: to-px
Created by: mikolalysenko
Last modified: Tue, 12 Jul 2022 06:49:47 GMT
Version: 1.1.0
License: MIT
Downloads: 1,229,526
Repository: https://github.com/mikolalysenko/to-px

Install

npm install to-px
yarn add to-px

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

Dependencies

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin