Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ab-mediaquery

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ab-mediaquery

AB-mediaQuery is the JavaScript side of media queries. It proposes you some very useful methods for your scripts

  • 2.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
decreased by-7.14%
Maintainers
1
Weekly downloads
 
Created
Source

AB-mediaQuery

AB-mediaQuery is the JavaScript side of Media Queries. It's a very simple, yet convenient tool for your developments.

This dependencie free and vanilla script is damn small: less than 1.3KB (uglyfied and GZipped)!

Have a look at this demonstration (offline version in the docs folder).

Version 1 is used on French websites of ENGIE and Gaz tarif règlementé.

Maintainability

Install

npm install --save ab-mediaquery

Setup

Import in your JS bundle (webpack, ES6, browserify...):

import abMediaQuery from 'ab-mediaquery';

Built version are also available in the dist folder if your are not using a bundler.

Init the script with:

AB.plugins.mediaQuery({
  bp: {
    smallOnly:  'screen and (max-width: 767px)',
    mediumOnly: 'screen and (min-width: 768px) and (max-width: 1024px)',
    medium:     'screen and (min-width: 768px)',
    largeOnly:  'screen and (min-width: 1025px) and (max-width: 1280px)',
    large:      'screen and (min-width: 1025px)'
  }
});

Other example:

AB.plugins.mediaQuery({
  bp: {
    tiny: "screen and (max-width: 575px)",
    small: "screen and (min-width: 576px)",
    medium: "screen and (min-width: 768px)",
    large: "screen and (min-width: 992px)",
    huge: "screen and (min-width: 1200px)"
  }
});

Usage

  • Get current breakpoints

    AB.mediaQuery.current;
    // return an array of current breakpoints
    
  • Check specific breakpoint case

    AB.mediaQuery.is('mediumOnly');
    // will return true or false
    
  • JavaScript event changed.ab-mediaquery event is triggered when media query changes, you can listen to it:

    window.addEventListener('changed.ab-mediaquery', function(){
      ...
    });
    

Keywords

FAQs

Package last updated on 14 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc