Skip to content

Instantly share code, notes, and snippets.

@gogones
Created July 2, 2024 06:57
Show Gist options
  • Save gogones/2c511209a61fa549a1f75896b94dc449 to your computer and use it in GitHub Desktop.
Save gogones/2c511209a61fa549a1f75896b94dc449 to your computer and use it in GitHub Desktop.
Get value vw/vh from px given relative to screen define
export const pxToVw = (px: number, windowWidth?: number) =>
`${(px / (windowWidth ?? window.innerWidth)) * 100}vw`;
export const pxToVh = (px: number, windowHeight?: number) =>
`${(px / (windowHeight ?? window.innerHeight)) * 100}vh`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment