Skip to content

Instantly share code, notes, and snippets.

@eiskalteschatten
Created May 31, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiskalteschatten/7e22105d6cd9e6ea37c05b0c80aadd6d to your computer and use it in GitHub Desktop.
Save eiskalteschatten/7e22105d6cd9e6ea37c05b0c80aadd6d to your computer and use it in GitHub Desktop.
A small script to determine viewport widths based on Bootstrap breakpoints.
// View port widths from Bootstrap
export const xs = 0;
export const sm = 576;
export const md = 768;
export const lg = 992;
export const xl = 1200;
export const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
export const isSmDown = (): boolean => vw <= sm;
export const isMdDown = (): boolean => vw <= md;
export const isLgDown = (): boolean => vw <= lg;
export const isSmUp = (): boolean => vw >= sm;
export const isMdUp = (): boolean => vw >= md;
export const isLgUp = (): boolean => vw >= lg;
export const isXs = (): boolean => vw <= xs;
export const isSm = (): boolean => vw >= sm && vw < md;
export const isMd = (): boolean => vw >= md && vw < lg;
export const isLg = (): boolean => vw >= lg && vw < xl;
export const isXl = (): boolean => vw >= xl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment