Functions
pxToViewport()
pxToViewport(
value,options):string
数值由 px 转为 viewport 并携带单位
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | 数值 |
options | PxToViewportOptions | 配置项 |
Returns
string
Example
ts
pxToViewport.defaults = {
unit: 'vw',
designWidth: 1440,
precision: 4,
}
pxToViewport(100)
// => '${((100 / 1440) * 100).toFixed(4)}${vw}'Interfaces
PxToViewportOptions
Properties
| Property | Type | Description |
|---|---|---|
designHeight? | number | 设计稿高度 Default 1080 |
designWidth? | number | 设计稿宽度 Default 1920 |
precision? | number | 小数精度 Default 6 |
unit? | "vw" | "vh" | "vmin" | "vmax" | 转换后的单位 Default 'vw' |