wiggle
Small wrapper around matchMedia
to easily react on changes in page layout. Define your own breakpoints in layout and react to them from JavaScript code.
var screen = Wiggle.init([{
name: 'desktop',
minWidth: 992
}, {
name: 'tablet',
minWidth: '768',
maxWidth: '62em'
}, {
name: 'mobile',
maxWidth: 767
}]);
screen.on('mobile', function() {
console.log('Function that will be executed if current screen size is mobile and every time screen size switches to mobile');
});
screen.on.change('mobile', function() {
console.log('Function that will be executed every time screen size switches to mobile.');
});
screen.on('desktop', function() {
console.log('Screen size is desktop');
});
screen.off('tablet', function() {
console.log('function that will be executed if screen size is not tablet and every time screen size stops being tablet');
});
screen.off.change('desktop', function() {
console.log('function that will be executed every time screen size stops being mobile');
});
if(screen.is('desktop')) {
console.log('Current screen size is desktop');
}
var orientation = Wiggle.init([{
name: 'portrait',
mediaQuery: '(orientation: portrait)'
}, {
name: 'landscape',
mediaQuery: '(orientation: landscape)'
}]);
orientation.on('portrait', function() {
console.log('function that will be executed if screen is in portrait mode and every time screen switches to portrait mode');
});
Supported browsers
Wiggle is using matchMedia to detect layout changes.
matchMedia is not supported in IE9 and below.