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

smooth-scroll-operator

v5.0.7

Published

A dead simple and lightweight smooth scroll animation utility. Scroll any element. Comes with bezier curve support and a small library of pre-defined easing functions. Animations respect clock.

Downloads

38

Readme

smooth-scroll-operator

A dead simple and lightweight library to animate the scroll of the window or any HTMLElement.

No need to ask, he's a smooth operator...

  • Really small filesize, only 1 dependency (~3KB uncompressed, including dependencies).
  • Supports Beizer Curves and custom easing functions, with predefined values.
  • Custom timing function (uses RAF by default if available)
  • Pause/resume/stop/restart
  • Animations respect the actual clock, so no matter the frame rate, the animation will still properly last the appropriate amount of time.

Installation

NPM:

npm i smooth-scroll-operator

browser:

You can use either smooth-scroll-operator.umd.js or smooth-scroll-operator.min.umd.js from the latest release in a script tag. This includes all dependencies.

<script src="smooth-scroll-operator.min.umd.js"></script>
<script>
    SmoothScrollOperator.scrollY(window, 500);
</script>

Example Usage

import sso from 'smooth-scroll-operator';

let el = document.querySelector('.myElement');

//scroll el to 500
sso.scrollY(el, 500);

// Scroll to y = 500, with a duration of 200ms, and a custom cubic-bezier easing function:
sso.scrollY(el, 500, {
  duration: 200,
  easing: [0.42, 0.0, 0.58, 1.0]
});

// Scroll to y = 500, with a duration of 200ms, and a pre-defined easing function.
sso.scrollY(el, 500, {
  duration: 200,
  easing: sso.EASING.EASE_IN
});

//scroll window
sso.scrollY(window, 500);

//Scroll and then pause animation 300ms later.
let animation = sso.scrollY(el, 500);

setTimeout(() => {
  
  animation.pause();
  
}, 300);

//resume 400ms later.
setTimeout(() => {
  
  animation.resume();
  
}, 400);

//Scroll and then immediately stop animation
let animation = sso.scrollY(window, 500);

animation.stop();

API

scrollY({HTMLElement|window} el, {number} targetY, {object=} options)

Animates the scrolling of a given element (scrolls to target position). Returns an instance of DOMAnimate. You can stop, pause, or resume the animation by calling .stop(), .pause(), or .resume(), respectively, on the returned instance.

{HTMLElement} el

The element to scroll. Can be window.

{number} targetY

The y position to animate/scroll to in pixels.

{object=} options

An optional map of parameters:

{integer} duration

Animation duration in milliseconds. (Default: 400)

{array} easing

An array to pass to the cubic-bezier easing function. (Default: SmoothScrollOperator.EASE_IN_OUT)

{function} onComplete

A callback function that is called when the animation is finished.

Constants

EASING

smooth-scroll-operator ships with a small Bezier Curve library:

  • EASING.EASE
  • EASING.EASE_IN
  • EASING.EASE_OUT
  • EASING.EASE_IN_OUT
  • EASING.LINEAR

License

MIT. Free to use in all your things!

Contribution

DO IT! PR's welcome. Need to add testing, linting, and support for scrollX, or both x/y at the same time.