-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derek Burgman
committed
Jan 30, 2022
1 parent
84cbdf2
commit 10b86b4
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './lib/window'; | ||
export * from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './window'; | ||
export * from './vh100'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// https://dev.to/maciejtrzcinski/100vh-problem-with-ios-safari-3ge9 | ||
|
||
export const DEFAULT_VH100_VARIABLE_NAME = 'vh100'; | ||
|
||
export function refreshVh100Function(cssVariableName = DEFAULT_VH100_VARIABLE_NAME) { | ||
const cssProperty = `--${cssVariableName}`; | ||
return () => { | ||
const doc = document.documentElement; | ||
doc.style.setProperty(cssProperty, `${window.innerHeight}px`); | ||
} | ||
}; | ||
|
||
/** | ||
* Adds window event listeners to populate the css variable `vh100`, or another input variable name, with the current window height. | ||
*/ | ||
export function watchWindowAndUpdateVh100StyleProperty(cssVariableName?: string) { | ||
const refreshPropertyValue = refreshVh100Function(cssVariableName); | ||
|
||
window.addEventListener('resize', refreshPropertyValue); | ||
window.addEventListener('orientationchange', refreshPropertyValue); | ||
refreshPropertyValue(); | ||
|
||
} |