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

tinyscroll

v3.1.0

Published

A tiny scrolling library for your in-page links

Downloads

40

Readme

Tiny Scroll

A tiny scrolling library for your in-page links.

  • Plain old vanilla JS.
  • Just 1.7kb gzipped.
  • Uses requestAnimationFrame for great performance.
  • Does not block user scroll.

Examples

Codepen

Alternatively, take a look in /examples.

Installation

npm install tinyscroll

The init function

The Tiny Scroll init function looks for all in page links with a certain class name (by default js-tinyscroll), and replaces the default click behaviour with a smooth scrolling action.

Usage

<a href="#hello-world" class="js-tinyscroll">
  Scroll to Hello World section
</a>

<section id="hello-world">
  <h1>Hello world</h1>
</section>
import * as tinyscroll from 'tinyscroll'
tinyscroll.init()

Options

The init function can optionally take an object as the first argument, that may include the following properties.

className

The class name that Tiny Scroll uses to locate links. Defaults to js-tinyscroll.

tinyscroll.init({ className: 'my-special-class' })

duration

The scroll duration in milliseconds. Defaults to 2000.

tinyscroll.init({ duration: 500 })

ease

The tweening function that is used to ease scroll position. Defaults to easeInOutQuint. Only easeInOutQuint is built in. Using this property will require you to import and use a function from tween-functions.

import ease from 'tween-functions'
tinyscroll.init({ ease: ease.easeOutElastic })

onStart

A callback function triggered when scroll starts.

tinyscroll.init({
  onStart: () => alert('Scroll started')
})

onComplete

A callback function triggered when scroll is complete.

tinyscroll.init({
  onComplete: () => alert('Scroll complete')
})

onCancel

A callback function triggered if scroll is cancelled by user.

tinyscroll.init({
  onCancel: () => alert('Scroll cancelled')
})

The scrollTo function

The scrollTo function is used to smoothly scroll to any element within a page. A target DOM node must be passed into the scrollTo function as the first argument.

Usage

<button type="button">
  Scroll to Hello World section
</button>

<section>
  <h1>Hello world</h1>
</section>
import * as tinyscroll from 'tinyscroll'

const trigger = document.querySelector('button')
const target = document.querySelector('section')

trigger.addEventListener('click', () => {
  tinyscroll.scrollTo(target)
})

Options

The scrollTo function can optionally take an object as the second argument, that may include the following properties.

duration

The scroll duration in milliseconds. Defaults to 2000.

tinyscroll.scrollTo(target, { duration: 500 })

ease

The tweening function that is used to ease scroll position. Defaults to easeInOutQuint. Only easeInOutQuint is built in. Using this property will require you to import and use a function from tween-functions.

import ease from 'tween-functions'
tinyscroll.scrollTo(target, { ease: ease.easeOutElastic })

offset

The number of pixels to offset the scroll to endpoint by. Defaults to 0.

tinyscroll.scrollTo(target, { offset: -200 })

onStart

A callback function triggered when scroll starts.

tinyscroll.scrollTo(target, {
  onStart: () => alert('Scroll started')
})

onComplete

A callback function triggered when scroll is complete.

tinyscroll.scrollTo(target, {
  onComplete: () => alert('Scroll complete')
})

onCancel

A callback function triggered if scroll is cancelled by user.

tinyscroll.scrollTo(target, {
  onCancel: () => alert('Scroll cancelled')
})

Data attributes

It can be useful to override Tiny Scroll's options on a case-by-case basis.

duration

In the following case the duration will be 500ms. The tinyscroll duration option is overridden by the data-duration attribute on the anchor element.

<a
  href="#hello-world"
  class="js-tinyscroll"
  data-duration="500"
>
  Scroll to Hello World section
</a>

<section id="hello-world">
  <h1>Hello world</h1>
</section>
import * as tinyscroll from 'tinyscroll'
tinyscroll.init({ duration: 3000 })

Browser support

Tiny Scroll is packaged with Babel, and makes use of Array.from. If you want Tiny Scroll to work on browsers that don't support this method (e.g. IE11), then you will need to polyfill Array.from before calling tinyscroll.