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

@mashvp/smoothvp

v0.1.4

Published

Scroll inertia smoothing

Downloads

3

Readme

Smoothvp

A native JavaScript scroll inertia smoothing library. Pronounced "Smooth up".

Installation

With npm

npm i @mashvp/smoothvp

With yarn

yarn add @mashvp/smoothvp

Usage

  • ES6: Import the default Smoothvp function
  • 1998 script tag: You can use the global window.Smoothvp function

Smoothvp#smooth

Given the HTML structure:

<body>
  <main id="container">
    <section id="content">
      <p>Some content...</p>
    </section>
  </main>
</body>

Use smooth to initialize the library on your container. Smoothvp works for both vertical and horizontal layouts.

import Smoothvp from '@mashvp/smoothvp';

document.addEventListener('DOMContentLoaded', () => {
  const container = document.getElementById('container');
  const content = document.getElementById('content');

  const smoothvp = Smoothvp(container, content, {
    direction: Smoothvp.Direction.VERTICAL,
  });

  smoothvp.smooth({
    duration: 500,
    timingFunction: Smoothvp.Easing.EASE_OUT_CUBIC,
  });
});

Note: As of today, the horizontal mode rotates your layout, and allows you to add the smoothvp-rotate class on the elements you want to rotate back. This works better with regular grid layouts, but will not work for everyone.

Smoothvp#scrollTo

Use scrollTo to programmatically scroll to a specific point or element in your page.

// Scroll to a specific point in the page
smoothvp.scrollTo(512);

// Scroll to an element (centered in viewport by default)
const element = document.querySelector('...');
smoothvp.scrollTo(element);

// Scroll to an element, aligned to the top of the viewport, with an offset of -70.
// The TOP and BOTTOM alignments align to the left and right in horizontal mode.
// If your site has a floating navbar, you can use the offset value to dodge it.
smoothvp.scrollTo(element, { position: Smoothvp.Position.TOP, offset: -70 });

Smoothvp#unsmooth

Call the unsmooth function on your Smoothvp instance to disable smoothing.

Options

duration

Duration of the smoothing effect, in milliseconds. Defaults to 700ms.

timingFunction

The CSS timing function to use for the smoothing effect. Any builtin CSS function or cubic-bezier can be used.

Constants

Easings

Smoothvp provides builtin easing helpers, available under Smoothvp.Easing.

| Name | Corresponding value | | -------------- | --------------------------------------- | | EASE_OUT_SINE | cubic-bezier(0.39, 0.575, 0.565, 1) | | EASE_OUT_CUBIC | cubic-bezier(0.215, 0.61, 0.355, 1) | | EASE_OUT_QUINT | cubic-bezier(0.23, 1, 0.32, 1) | | EASE_OUT_CIRC | cubic-bezier(0.075, 0.82, 0.165, 1) | | EASE_OUT_QUAD | cubic-bezier(0.25, 0.46, 0.45, 0.94) | | EASE_OUT_QUART | cubic-bezier(0.165, 0.84, 0.44, 1) | | EASE_OUT_EXPO | cubic-bezier(0.19, 1, 0.22, 1) | | EASE_OUT_BACK | cubic-bezier(0.175, 0.885, 0.32, 1.275) |

Events

You can listen to the update event to get the scroll position on every update.

import Smoothvp from '@mashvp/smoothvp';

document.addEventListener('DOMContentLoaded', () => {
  const container = document.getElementById('container');
  const content = document.getElementById('content');

  const smoothvp = Smoothvp(container, content);
  smoothvp.smooth();

  smoothvp.addEventListener('update', event => {
    const { top } = event;

    console.log(top);
  });
});

You can also use removeEventListener like on any HTML element.

Credits