Skip to content

kimulaco/mqfunctions

Repository files navigation

mqfunctions

Test Status License MIT npm version codecov

JavaScript library to manage matchMedia handlers.

Install

npm install mqfunctions

Use

import { createMqFunctions } from 'mqfunctions'

const mqf = createMqFunctions('(min-width: 768px)')

// Add matchMedia handler
mqf.add('function-01', (event) => {
  if (event.matches) {
    console.log('Resized window to PC size!')
  } else {
    console.log('Resized window to SP size!')
  }
})

// Run handler arbitrarily
mqf.run('function-01')

// Remove handler
mqf.remove('function-01')

License

MIT License.