device.js 744 B

123456789101112131415161718192021222324252627282930313233
  1. import enquireJs from 'enquire.js'
  2. export const DEVICE_TYPE = {
  3. DESKTOP: 'desktop',
  4. TABLET: 'tablet',
  5. MOBILE: 'mobile'
  6. }
  7. export const deviceEnquire = function (callback) {
  8. const matchDesktop = {
  9. match: () => {
  10. callback && callback(DEVICE_TYPE.DESKTOP)
  11. }
  12. }
  13. const matchLablet = {
  14. match: () => {
  15. callback && callback(DEVICE_TYPE.TABLET)
  16. }
  17. }
  18. const matchMobile = {
  19. match: () => {
  20. callback && callback(DEVICE_TYPE.MOBILE)
  21. }
  22. }
  23. // screen and (max-width: 1087.99px)
  24. enquireJs
  25. .register('screen and (max-width: 576px)', matchMobile)
  26. .register('screen and (min-width: 576px) and (max-width: 1199px)', matchLablet)
  27. .register('screen and (min-width: 1200px)', matchDesktop)
  28. }