feat(Sticky): offset-top support vh unit (#7498)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user