Skip to content

pxToViewport

Namespaces

Functions

pxToViewport()

pxToViewport(value, options): string

数值由 px 转为 viewport 并携带单位

Parameters

ParameterTypeDescription
valuenumber数值
optionsPxToViewportOptions配置项

Returns

string

Example

ts
pxToViewport.defaults.unit = 'vw'
pxToViewport.defaults.designWidth = 1440
pxToViewport.defaults.precision = 4

pxToViewport(100)
// => '${((100 / 1440) * 100).toFixed(4)}${vw}'

Interfaces

PxToViewportOptions

Properties

PropertyTypeDescription
designHeight?number设计稿高度

Default
1080
designWidth?number设计稿宽度

Default
1920
precision?number小数精度

Default
6
unit?"vw" | "vh" | "vmin" | "vmax"转换后的单位

Default
'vw'