1.4.4 • Published 5 years ago

match-media-breakpoint v1.4.4

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

Match Media Breakpoint

Work with breakpoints through matchMedia.

Build Status Coverage Status npm npm npm David David

Demo and examples

Demo

VueJs simple example

Install

via NPM

npm install match-media-breakpoint --save

Usage

Define new instance of MatchMediaBreakpoint with providing breakpoints array at first parametr and callback as second parametr.

The array of breakpoints should consist of objects, the first property of which is the name of the breakpoint, and the second is the value from which the current breakpoint begins. For example:

import { MatchMediaBreakpoint } from 'match-media-breakpoint';

const breakpoints = [
  { breakpoint: 'mobile', width: 0 },
  { breakpoint: 'tablet', width: 768 },
  { breakpoint: 'laptop', width: 1180 },
  { breakpoint: 'desktop', width: 1440 },
];

const matchMediaBreakpoint = new MatchMediaBreakpoint({
  breakpoints, 
  onBreakpointChange: (currentBreakpoint, previousBreakpoint) => {
    console.log({ currentBreakpoint, previousBreakpoint });
  },
});

Properties

value

matchMediaBreakpoint.value // return current breakpoint

previousValue

matchMediaBreakpoint.previousValue // return previous breakpoint

Methods

subscribe()

matchMediaBreakpoint.subscribe(handler) // add listener. The hander will be called with the previous and current breakpoint as parameters at each breakpoint change

unsubscribe()

matchMediaBreakpoint.subscribe(handler) // remove listener.

destroy()

matchMediaBreakpoint.destroy() // remove all listeners

License

This project is licensed under the MIT license, Copyright (c) 2018 karambafe. For more information see LICENSE.

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago