-
Notifications
You must be signed in to change notification settings - Fork 0
getCurrentMediaQuery
Mike Byrne edited this page Jan 25, 2022
·
6 revisions
Returns the current media query in use by looking at the font-family of the head of the document and text in pseudo content on the body. Useful for running JS functions at certain breakpoints without holding breakpoint size information in CSS and JS.
- specific HTML
- none
- media query string as a string
var mq = getCurrentMediaQuery(); // returns 'large' (if viewport at large size)body:after {
font: 0/0 a;
color: transparent;
text-shadow: none;
width: 1px;
height: 1px;
margin: -1px 0 0 -1px;
position: absolute;
left: -1px;
top: -1px;
}
@media (max-width: 767px) {
head {
font-family: 'small';
}
body:after {
content: 'small';
}
}
@media (max-width: 768px) {
head {
font-family: 'medium';
}
body:after {
content: 'medium';
}
}