feat: Add px to responsive min/max vw in inline styles

This commit is contained in:
CharleeWa 2024-08-01 21:26:34 +08:00
parent 88f2d33e02
commit b5a596faeb
2 changed files with 19 additions and 6 deletions

View File

@ -2,7 +2,7 @@
"name": "vue3-vant-mobile",
"type": "module",
"version": "2.3.7",
"packageManager": "pnpm@9.4.0",
"packageManager": "pnpm@9.6.0",
"description": "Vue + Vite H5 Starter Template",
"license": "MIT",
"scripts": {

View File

@ -1,15 +1,28 @@
/**
* px vw
* scale-view
* https://github.com/wswmsword/scale-view
* @wswmsword
*/
import { round } from 'lodash-es'
// 设计稿的宽度
const width = 375
// 理想宽度,设计稿的宽度
const idealWidth = 375
// 表示伸缩视图的最大宽度
const maxWidth = 600
/**
* vw
* vw
* @param {number} n
*/
export default function vw(n: number) {
if (n === 0)
return n
const vwN = round(n * 100 / width, 3)
return `${vwN}vw`
const vwN = round(n * 100 / idealWidth, 3)
const maxN = round(n * maxWidth / idealWidth, 3)
const cssF = n > 0 ? 'min' : 'max'
return `${cssF}(${vwN}vw, ${maxN}px)`
}