File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 22 "name" : " vue3-vant-mobile" ,
33 "type" : " module" ,
44 "version" : " 2.3.7" ,
5- "packageManager" : " pnpm@9.4 .0" ,
5+ "packageManager" : " pnpm@9.6 .0" ,
66 "description" : " Vue + Vite H5 Starter Template" ,
77 "license" : " MIT" ,
88 "scripts" : {
Original file line number Diff line number Diff line change 1+ /**
2+ * 支持行内样式 px 转 vw
3+ * 本文件代码来自于 scale-view 开源项目
4+ * 源代码链接:https://github.com/wswmsword/scale-view
5+ * 非常感谢作者 @wswmsword 的支持
6+ */
7+
18import { round } from 'lodash-es'
29
3- // 设计稿的宽度
4- const width = 375
10+ // 理想宽度,设计稿的宽度
11+ const idealWidth = 375
12+
13+ // 表示伸缩视图的最大宽度
14+ const maxWidth = 600
515
616/**
7- * vw 转换
17+ * 限制大小的 vw 转换
818 * @param {number } n
919 */
1020export default function vw ( n : number ) {
1121 if ( n === 0 )
1222 return n
13- const vwN = round ( n * 100 / width , 3 )
14- return `${ vwN } vw`
23+
24+ const vwN = round ( n * 100 / idealWidth , 3 )
25+ const maxN = round ( n * maxWidth / idealWidth , 3 )
26+ const cssF = n > 0 ? 'min' : 'max'
27+ return `${ cssF } (${ vwN } vw, ${ maxN } px)`
1528}
You can’t perform that action at this time.
0 commit comments