Skip to content

Instantly share code, notes, and snippets.

@syammohanmp
Created November 16, 2022 15:36
Show Gist options
  • Save syammohanmp/7aa4317d9613c15412ab0bbb8b2e119a to your computer and use it in GitHub Desktop.
Save syammohanmp/7aa4317d9613c15412ab0bbb8b2e119a to your computer and use it in GitHub Desktop.
Media detection JavaScript functions
const breakpoints = {
xs: 480,
sm: 768,
md: 1024,
lg: 1280,
xl: 1440
}
function minWidth(screensize){
return window.matchMedia(`(min-width: ${screensize}px)`);
}
function maxWidth(screensize){
return window.matchMedia(`(max-width: ${screensize}px`);
}
// Usage
// Check the device width less that medium
// if (!minWidth(breakpoints.screenMl).matches) { console.log('You are in XS or SM') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment