npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

responsive-slider

v1.0.0

Published

Responsive Slider with everything you need

Downloads

2

Readme

CSS Media query in JS

npm npm

Installation

npm install js-media-query

Usage

import Media from "js-media-query";
import { up, sm, md } from "js-media-query";

See Examples

API

| Method | Description | | ---------------- | ---------------------------------------------------------------- | | query | Check media query matching | | min | Minimum breakpoint width | | max | Maximum breakpoint width | | up | Minimum breakpoint width | | down | Maximum breakpoint width | | between | Check if screen between the from and to breakpoints | | isTouch | Check if is touck device | | isMouse | Check if is non-touch device | | xs | Check if screen is bigger or equal to xs class defined breapoint | | sm | Check if screen is bigger or equal to sm class defined breapoint | | md | Check if screen is bigger or equal to md class defined breapoint | | lg | Check if screen is bigger or equal to lg class defined breapoint | | xl | Check if screen is bigger or equal to xl class defined breapoint | | setBreakpoints | Set Local class breapoints |

Events

on(event, callback, media)

| Prop | Value | Required | Description | | ---------- | ------------------------ | :------: | ------------------------------------------------------------- | | event | in , out , changed | yes | Event type | | callback | function | yes | Callback function reference | | media | function | yes | Function reference what return result of required media query |

off(event, callback?, media?)

| Prop | Value | Required | Description | | ---------- | ------------------------ | :------: | ------------------------------------------------------------- | | event | in , out , changed | yes | Event type | | callback | function | yes | Callback function reference | | media | function | yes | Function reference what return result of required media query |

Examples

Basic Usage

import { min } from "js-media-query";

window.addEventListener("resize", () => {
  if (min(992)) {
    console.log("Screen size is equals or bigger than 992px");
  } else {
    console.log("Screen size is lower than 992px");
  }
});

Using with default breakpoints

import Media from "js-media-query";

if (Media.sm()) {
  // Your code
}

Using with custom breakpoints

import { Media } from "js-media-query";

const media = new Media({
  xs: 0,
  sm: 576,
  md: 768,
  lg: 992,
  xl: 1200,
});

if (media.md()) {
  // Execute code if screen size is bigger or equals to 768px
}

Event listening

import { Media } from "js-media-query";

const media = new Media();

const changedHandler = () => {
  console.log("changed");
};

const mediaFn = () => media.up(768);

// Add event listener
media.on("changed", changedHandler, mediaFn);

// Remove all event listeners of event type
media.off("changed");

// Remove event listener of event type
media.off("changed", changedHandler);

// Remove event listener of event type on with specific media function
media.off("changed", changedHandler, mediaFn);

@media (min-width: 768px) AND (max-width: 992px)

Media.between(768, 992); // true | false

@media (pointer: coarse)

Media.isTouch(); // true | false

@media (min-width: 992px)

Media.min(992); // true | false

@media (max-width: 991px)

Media.down(991); // true | false

@media (min-width: 1200px)

Media.xl(); // true | false