1.0.5 • Published 8 years ago

media-query-event v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

media-query-event

a module that help you detect CSS media query changing event and run the callback function.

Installation

npm install media-query-event --save

Usage

var mediaQueryEvent = require('media-query-event');
mediaQueryEvent.bind(range, callback, callbackWhenPageInit);

range

TypeExample ValueDescription
single rangestring'xs', 'sm', 'md', 'lg'由其他 range 進入到這個 range 時,觸發 callback function
multiple rangearray'xs', 'sm'由陣列以外的 range 進入到陣列中這些 range 時,觸發 callback function

callback

TypeDescription
functionA callback function that you want to run when media query is changing.

callbackWhenPageInit

TypeExample ValueDefault ValueDescription
booleantrue, falsefalseRun the callback function when the web page initialized.

Example

Single Range

mediaQueryEvent.bind('sm', function() {
  alert('sm');
});

Multiple Range

mediaQueryEvent.bind(['md', 'lg'], function() {
  alert('desktop');
});

Run callback when the page initialized

mediaQueryEvent.bind('sm', function() {
  alert('sm');
}, true);

About more examples, please see the "demo" directory.