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

relativity

v1.0.1-beta

Published

Super smooth animations on scroll.

Downloads

24

Readme

Relativity

Relativity is a library that uses screen scroll events and position to animate elements within the viewport. It can be used to create a parallax effect, scaling, rotations, fade in and out, and so much more.

Installation

npm install --save relativity

bower install relativity

Usage

Relativity uses jQuery for DOM manipulation so you'll need that to be available before Relativity.

<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="relativity.js"></script>

Relativity makes itself available as a global variable which you can use to create a new instance like this:

var relativity = new Relativity(options);

Options

There are a number of options that you can use when initializing Relativity. You can either pass a JSON array into options.containers which describes the containers and the elements inside them or you can defined the containers and movements in your HTML and let Relativity find them.

| Option | Type | Values | Description | | -------------------- | ---------- | ------------------------ | --------------------------------------------------------------------- | | positionPropery | String | transform / position | Specificies whether to use CSS3 transforms or top/left positioning to move objects | supports3D | Boolean | true / false | Specificies whether to use CSS3 transform3d or transform | | containers | Array | [] | Specifies which elements to use as containers and the elements within them |

Movements

Relativity includes a number of built in movements that you can use to animate elements inside of containers.

Left | Right | Up | Down

Reveal

Scale

Events

Relativity also fires off events if you need more control over the animations or want to use Relativity as a waypoints solution.

On Screen

When a container is on screen it will trigger an event after every window.scroll event. You can listen to it like this:

$('.myContainer').on('relativity:onscreen', function(event, container, percentage) {
	console.log(container);
	// { top: '', bottom: '', height: '', $element: '', elements: [], elementsCount: 0 }
});

Off Screen

When a container switches from being on screen to off screen it will trigger a single event and include a direction parameter that can be up or down.

$('.myContainer').on('relativity:offscreen', function(event, container, direction) {
	console.log(container);
	// { top: '', bottom: '', height: '', $element: '', elements: [], elementsCount: 0 }

	console.log(direction);
	// 'up' | 'down'
});

Update Elements

Relativity needs to know a few things about the page height and screen size in order to accurately calculate which elements are on screen. It already includes a listener to detect screen resize events however these don't detect changes to the height of the page if something is added to the DOM. If you add anything to the DOM or adjust the height of an element dynamically you will need to ask Relativity to recalculate everything. It's super simple though, just trigger an event on the document like this:

$(document).trigger('relativity:update');