feat(Sticky): offset-top support vh unit (#7498)

This commit is contained in:
neverland
2020-11-04 19:39:52 +08:00
committed by GitHub
parent ce619c67e2
commit ebd78a9d02
12 changed files with 22 additions and 11 deletions
+8 -1
View File
@@ -35,6 +35,11 @@ function convertVw(value: string) {
return (+value * window.innerWidth) / 100;
}
function convertVh(value: string) {
value = value.replace(/vh/g, '');
return (+value * window.innerHeight) / 100;
}
export function unitToPx(value: string | number): number {
if (typeof value === 'number') {
return value;
@@ -44,10 +49,12 @@ export function unitToPx(value: string | number): number {
if (value.indexOf('rem') !== -1) {
return convertRem(value);
}
if (value.indexOf('vw') !== -1) {
return convertVw(value);
}
if (value.indexOf('vh') !== -1) {
return convertVh(value);
}
}
return parseFloat(value);