resizejs
v0.0.1
Published
Resize JS is a tiny plugin to implement responsive events
Downloads
1
Maintainers
Readme
ResizeJS
Resize JS is a tiny plugin to implement responsive events
Install
npm install --save resizejs
Usage
Basic
import Resizable from 'resizejs';
const resp = new Resizable();
window.addEventListener('media.changed', () => {
const media = resp.getMedia();
const orientation = resp.getOrientation();
});
On orientation change
import Resizable from 'resizejs';
const resp = new Resizable({
enableOrientationChange: true
});
window.addEventListener('media.changed', () => {
const media = resp.getMedia();
const orientation = resp.getOrientation();
});
Customize breakpoints
import Resizable from 'resizejs';
const resp = new Resizable({
breakpoints: {
mobile: 320,
mobileLarge: 414,
tablet: 768,
tabletLarge: 1024,
desktop: 1200
}
});
window.addEventListener('media.changed', () => {
const media = resp.getMedia();
const orientation = resp.getOrientation();
});
Only when base media changes
For example: Tablet to Desktop or Mobile to Tablet
import Resizable from 'resizejs';
const resp = new Resizable({
breakpoints: {
mobile: 320,
mobileLarge: 414,
tablet: 768,
tabletLarge: 1024,
desktop: 1200
}
});
window.addEventListener('basemedia.changed', () => {
const media = resp.getMedia();
const orientation = resp.getOrientation();
});
Note
This library uses window.matchMedia
. To support old browsers please use a polyfill.