-
Notifications
You must be signed in to change notification settings - Fork 0
getCurrentMediaQuery
Mike Byrne edited this page Aug 24, 2022
·
6 revisions
Returns the current media query in use by reading a CSS :root variable.
Useful for running JS functions at certain breakpoints without holding breakpoint size information in CSS and JS.
- specific CSS
:root {
--breakpoint: "xs";
}
@media (min-width: 544px) {
:root {
--breakpoint: "sm";
}
}
@media (min-width: 650px) {
:root {
--breakpoint: "md";
}
}
@media (min-width: 990px) {
:root {
--breakpoint: "lg";
}
}
@media (min-width: 1300px) {
:root {
--breakpoint: "xl";
}
}
@media (min-width: 1520px) {
:root {
--breakpoint: "xxl";
}
}- none
- media query string as a string
var mq = getCurrentMediaQuery(); // returns 'lg' (if viewport at lg size)