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

@timroussilhe/smooth

v0.2.3

Published

Smooth plugin that allow all basic scroll interactions

Downloads

2

Readme

Smooth

enter image description here

What's Smooth?

Custom library to handle scroll.

There is 3 main things that Smooth can take care of for you :

  • Wrapping a container ( usually the page ) and adding a smooth scroll ( with some lerping/momemtum to it )
    • This can be some by keeping the real scroll and scrollbar for a more native experience
    • Or this can be done using virtual-scroll for a more smooth experience
  • Handling Parallax
    • Smooth will act as a controller to handle parallax
  • Scroll Trigger, to reveal element when they reach a certain

The library works on mobile but I recommend to keep the real scroll on mobile.

Usage

HTML

<!DOCTYPE html>

<html lang="en">
  <head>
    <title>Title</title>
  </head>
  <body>
    <main id="content">
      <section class="page-wrapper">...</section>
    </main>
  </body>
</html>

Javascript

Create a smooth instance

import Smooth from '@timroussilhe/smooth';

this.smooth = new Smooth({
  scrollElement: document.querySelector('.scroll-wrapper'),
  scrollOptions: {
    useVirtualScroll: false,
    smoothContainer: true,
    easing: 0.12,
    friction: null,
  }
});

this.smooth.start();

Add Scroll Elements

const elementParallax = {
  el: document.querySelector('.scroll-wrapper'),

  parallax: [
    {
      start: 0,
      end: 500,
      properties: [['translateY', 0, 250]],
      easing: 'easeInOutCubic',
      viewFactorStart: 0,
      viewFactorEnd: 0,
    },
  ],
};

const $footer = document.querySelector('footer');

const elementTrigger = {
  el: $footer,

  trigger: {
    start: 'in-viewport',
    end: 'out-viewport',
    viewFactorStart: 0,
    viewFactorEnd: 0,
    callback: (before) => {
      if (before === 0) {
        $footer.classList.add('footer--in');
      } else if (before === -1) {
        $footer.classList.remove('footer--in');
      }
    },
  },
};
this.smooth.addElements([elementParallax, elementTrigger]);

Reflow/resize

this.smooth.reset(this.getScrollElement());
this.smooth.resize();

API

Smooth Properties/Options

| property | type | default | description | |------------------ |------------- |------------ |---------------------------------------------------- | | scrollElement | DOM element | null | required DOM element for the Scroll wrapper | | scrollbarElement | DOM element | null | optional DOM element for the Scrollbar container | | scrollOptions | Object | {} | required Option for the Scroll | | scrollbarOptions | Object | {} | optional Option for the Scroll |

Scroll Properties/Options

| property | type | default | description | |---------------------- |--------- |---------- |------------------------------------------------------------------------------------------ | | easing | number | 0.5 | easing value for the scroll | | friction | number | 0.2 | friction value for the scroll | | wheelDeltaMultiplier | number | 0.45 | Multiplier to add to the wheel delta | | maxWheel | number | 400 | Max value that the wheel event delta can get to | | autoUpdate | boolean | true | Let Scroll update its own requestanimationframe loop | | useVirtualScroll | boolean | true | Use virtual-scroll or the native scroll | | direction | string | vertical | Direction of the scroll, vertical or horizontal | | infinite | boolean | false | Infinite scroll will not stop the Scroll when reaching the limit of the scroll Wrapper. |

Scrollbar Properties/Options

| property | type | default | description | |-------------------- |---------- |----------------- |--------------------------------------------------- | | orientation | string | vertical | Orientation and placement of the scrollbar | | minSize | number | 50 | Smallest size that the Scrollbar thumb can reach | | fade | boolean | true | If the Scrollbar thumb need to fade or not | | fadeTime | number | 1200 | Fade Timer duration | | className | string | scrollbar-thumb | className of the generated Scrollbar | | updateScrollTarget | function | null | Function to called when the Scrollbar get updated |

Smooth Element Option

| property | type | description | |---------- |------------- |---------------------- | | el | DOM Element | Target element | | trigger | Object | Trigger Item values | | parallax | Array | Array of Parallax Item values |

Smooth Element Paralaxe

| property | type | description | |----------------- |------------------ |------------------------------------------------------------------------------------------------------------------------------------------------ | | start | string | number | start value for the scroll element. This can be a number or use 'in-viewport' 'out-viewport' | | end | string | number | end value for the scroll element. This can be a number or use 'in-viewport' 'out-viewport' | | properties | array | Properties to animate, each property should be an array following this structure [property,valueStart,ValueEnd] ex: ['translateY', 0, 200] | | viewFactorStart | string | number | factor to add to the start value, this can be a number that will be used as a factor of the element height or a fixed pixel value. Ex: 200px | | viewFactorEnd | string | number | factor to add to the end value, this can be a number that will be used as a factor of the element height or a fixed pixel value. Ex: 200px |

Smooth Element Trigger

| property | type | description | |----------------- |--------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------- | | start | string | number | start value for the scroll element. This can be a number or use 'in-viewport' 'out-viewport' | | end | string | number | end value for the scroll element. This can be a number or use 'in-viewport' 'out-viewport' | | viewFactorStart | string | number | factor to add to the start value, this can be a number that will be used as a factor of the element height or a fixed pixel value. Ex: 200px | | viewFactorEnd | string | number | factor to add to the end value, this can be a number that will be used as a factor of the element height or a fixed pixel value. Ex: 200px | | callback | function (scrollPosition) => {} | callback function to be called when the trigger start or end scroll values are reached. scrollPosition is -1 for before, 0 for in, 1 for after. | | repeat | boolean | Repeat the callback function after the first trigger in. |

Smooth Method

| Method | Description | |------------------------- |------------------------------------------------------------------------------------------------------------ | | start | Start Smooth | | addElements(elements) | Add Scroll Elements. Arguments: elements | | reset(elements) | Reset Scroll Elements. Usually used on resize | | disable | Disable Smooth | | enable | Enable Smooth | | scrollTo(target,direct) | Set Scroll Position. Arguments: target: scroll position. direct scroll to the target with no animation | | resize(target) | Resize Smooth. Arguments: target: you can provide a fixed height but this is not necessary | | destroy() | Destroy Smooth instance and clear events. |

Live Examples