Created
November 16, 2022 15:36
-
-
Save syammohanmp/7aa4317d9613c15412ab0bbb8b2e119a to your computer and use it in GitHub Desktop.
Media detection JavaScript functions
This file contains 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
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