Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This project is not covered by Drupal’s security advisory policy.
Use Drupal breakpoint media queries in your JavaScripts!
Given the following in the active theme's *.breakpoints.yml:
mobile:
label: mobile
mediaQuery: ''
weight: 0
multipliers:
- 1x
narrow:
label: narrow
mediaQuery: 'all and (min-width: 560px) and (max-width: 850px)'
weight: 1
multipliers:
- 1x
wide:
label: wide
mediaQuery: 'all and (min-width: 851px)'
weight: 2
multipliers:
- 1x
You can use your Drupal breakpoints with window.matchMedia in your conditions:
if (window.matchMedia(window.drupalSettings.jsBp["narrow"]).matches) {
console.log('Narrow');
} else {
console.log('Not narrow');
}
Or as events:
window.matchMedia(window.drupalSettings.jsBp["wide"]).addListener(
function(e){
if (e.matches) {
console.log('Wide');
} else {
console.log('Not wide');
}
});
Supporting organizations:
Project information
- Seeking new maintainer
The current maintainers are looking for new people to take ownership. - Module categories: Developer Tools
- Created by rattusrattus on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.