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

flamingo-carotene-smooth-scroll-to

v9.0.0-alpha.13

Published

The smooth scroll module enables to scroll smoothly to a given y coordinate or dom element

Downloads

31

Readme

Module flamingo-carotene-smooth-scroll-to

SmoothScrollTo is a small library, which allows the developer to scroll a page smoothly to a given Y coordinate or to a given dom element.

What it is for

Programmatically scrolling a page in a fancy, sparkling, smooth way

How to use

npm i -D flamingo-carotene-smooth-scroll-to

Import the library

import SmoothScrollTo from 'flamingo-carotene-smooth-scroll-to'

Scroll to a given domElement

const scrollToElement = document.getElementById('fooBar')
new SmoothScrollTo().scrollTo(scrollToElement)

or

Scrolling to 500 pixel

new SmoothScrollTo().scrollTo(500)

Setup

You can call different setters to change configuration

Animation Duration

Use setDuration() to change the overall animation time (in ms)

new SmoothScrollTo().setDuration(1000).scrollTo(500)

Scrolling Offset

Sometimes you dont want to respect the very top of the window (in case of sticky headers or similar). In this case you can use setOffset() to set an offset

new SmoothScrollTo().setOffset(50).scrollTo(500)

In this example the scrolling position will be at 450.

Interrupt, stopping or restarting

You can easily stop the animation by using stop() The current animation will be stopped automatically if you call scrollTo() while the animation is running.

Note: the FinishCallback will be fired at both situations.

Autointerrupt on manual scrolling

By default, the scrolling animation is automatically stopped and canceled if the user (or other code) is scrolling in an opposite direction while the library is scrolling. Use .setCancelAnimationOnUserScroll(false) to disable this feature.

Animation Callbacks

You can provide 2 callbacks:

  • AnimationStepCallback
  • FinishCallback

AnimationStepCallback

The animationStepCallback is called after each animation frame. Inside of this frame you can adjust animation settings, if you need to change the target or offset values while animating. (i.E. if you've got sticky headers, or elements which change its size while scrolling)

Note: If you're scrolling to a domElement - you don't need to readjust the target if the position of the target has changed while the animation runs. In this case the target position will be updated automatically. You can access the actual target position with getCurrentTargetY() and set it by setCurrentTargetY()

const sst = new SmoothScrollTo()
  .setOffset(50)
  .setAnimationStepCallback(function(sstInstance) {
    if (somethingHappend) {
      sstInstance.setOffset(100)
    }
  })
  .scrollTo(500)

FinishCallback

As the name suggests - this callback will be fired, if the animation is completed, stopped or restarted

const sst = new SmoothScrollTo()
  .setOffset(50)
  .setFinishCallback(function() {
    // do something here
  })
  .scrollTo(500)