Skip to content

Instantly share code, notes, and snippets.

@StrongerMyself
Created December 24, 2020 09:29
Show Gist options
  • Save StrongerMyself/afa4e47461ae01291ae5358d42d17e1d to your computer and use it in GitHub Desktop.
Save StrongerMyself/afa4e47461ae01291ae5358d42d17e1d to your computer and use it in GitHub Desktop.
const isMobile = {
android: () => navigator.userAgent.match(/Android/i),
blackberry: () => navigator.userAgent.match(/BlackBerry/i),
ios: () => navigator.userAgent.match(/iPhone|iPad|iPod/i),
opera: () => navigator.userAgent.match(/Opera Mini/i),
windows: () => navigator.userAgent.match(/IEMobile/i),
any: () => (
isMobile.android() ||
isMobile.blackberry() ||
isMobile.ios() ||
isMobile.opera() ||
isMobile.windows()
)
}
isMobile.any() ? document.body.classList.add('is-mobile') : null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment