Created
May 7, 2020 17:05
-
-
Save hieblmedia/79fe5a7628be43a977a7d0a7d56b4f89 to your computer and use it in GitHub Desktop.
Javascript to check (Bootstrap 4) breakpoints based on CSS variables
This file contains hidden or 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
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