Skip to content

scssyworks/resizejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Resize JS is a tiny plugin to implement responsive events

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published