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

viewporter-breakpoints

v2.0.0

Published

A Viewport Size and Breakpoint Detection Library for detecting and setting breakpoints

Downloads

2

Readme

Viewport Size and Breakpoint Detection Library

Viewporter is a library that simplifies cross device and browser sizing issues between client width, height, etc. It creates a class tied to which ever element(s) you want holding break points. The purpose is to alleviate the problems negotiating a viewport or actual client width's and provide a simple API for your styling to be able to be uniform across breakpoints.

Features

  • Retrieves the current viewport dimensions and updates it on resize or load events
  • Writes the viewport dimensions to a specified HTML element
  • Adds classes to a specified HTML element, based on the breakpoint values provided

Installation

You can install the library using npm:

npm install viewporter-breakpoints

Options

The following options can be passed when instantiating the Viewporter class:

| Option | Description | Default | | ------ | ----------- | ------- | | afixTo | The selector of the HTML element to add the breakpoint classes to | 'body' | | addEvents | A flag indicating whether to bind to the resize and load events | true | | writeOut | A flag indicating whether to write the viewport dimensions to a specified element | false | | writeTo | The selector of the HTML element to write the viewport dimensions to | '#viewporter_debug' | | classPrefix | The prefix to use for the breakpoint classes | 'breakp-' | | breakPoints | An array of breakpoints to determine the breakpoint classes | [320, 480, 640, 720, 960, 1024] | | viewportIni | The initial scale of the viewport meta tag | 1.0 | | viewportMax | The maximum scale of the viewport meta tag | 1.0 | | viewportScale | The user-scalable property of the viewport meta tag | 0 |

Usage

const viewporter = new Viewporter({
    afixTo: 'body',
    writeOut: true,
    breakPoints: [320, 480, 720, 1024],
});

Methods

getViewportSize: retrieves the current viewport dimensions writeStuff: writes the viewport dimensions to a specified HTML element addEvents: binds to the resize and load events handleResize: the callback for the resize event handleLoad: the callback for the load event setClasses: sets the breakpoint classes on a specified HTML element

Implementation

Here's how you can use the Viewporter class in your project:

Simple

const viewporter = new Viewporter({ breakPoints: ['480','768','1024'] });

Verbose

const options = {
afixTo: 'body',
addEvents: true,
writeOut: false,
writeTo: '#viewporter_debug',
classPrefix: 'breakp-',
breakPoints: [320, 480, 640, 720, 960, 1024],
viewportIni: 1.0,
viewportMax: 1.0,
viewportScale: 0
};

const viewporter = new Viewporter(options);

In the example above, we pass an options object to the Viewporter class that contains configuration settings. The afixTo property specifies the CSS selector to apply the breakpoint class to. The addEvents property sets whether to listen to the resize and load events. The writeOut property enables or disables writing the current viewport size to a DOM element specified by the writeTo selector. The classPrefix property sets a custom prefix for the breakpoint classes. The breakPoints property sets the breakpoint widths in pixels. The viewportIni, viewportMax, and viewportScale properties set the initial-scale, maximum-scale, and user-scalable values for the meta viewport tag.

You can customize these options as per your requirements.

OLD jQuery Implementation:

You must include files as needed (jquery, jquery.viewporter etc..), I will not be describing that here.

Basic:

<script>
	jQuery.viewporter({ breakPoints: ['480','600','768'] });
</script>

More Complex:

<script>
	jQuery.viewporter({ afixTo: 'body,.this-other-element', breakPoints: ['480','600','768'] });
</script>