Skip to content

Instantly share code, notes, and snippets.

@hieblmedia
Created May 7, 2020 17:05
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 hieblmedia/79fe5a7628be43a977a7d0a7d56b4f89 to your computer and use it in GitHub Desktop.
Save hieblmedia/79fe5a7628be43a977a7d0a7d56b4f89 to your computer and use it in GitHub Desktop.
Javascript to check (Bootstrap 4) breakpoints based on CSS variables
function matchBreakpoint(breakpoint) {
var value = window.getComputedStyle(document.documentElement).getPropertyValue('--breakpoint-' + breakpoint);
return window.matchMedia("(min-width: " + value + ")").matches;
}
// Example:
// matchBreakpoint('md') ? 'its md' : 'meh';
// You can also use this if you provide CSS variables with --breakpoint-[breakpoint] in your custom CSS or on other frameworks.
// It's simple to adapt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment