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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sqroll

v1.1.3

Published

Another scrolling library

Downloads

52

Readme

sqroll

Sqroll is another scrolling library, with a simple api and a small overhead.

Install

Download source or npm install sqroll.

Include script dist/sqroll.min.js as a script tag or include in source:

const sqroll = require('sqroll');

import sqroll from 'sqroll';

You might need to polyfill requestAnimationFrame().

API & Usage

Create an instance, add triggers and then start the listener:

const sq = sqroll();

// add triggers...

sq.start();

sq.trigger(el, options)

This is the most basic method. It'll fire a callback function when an element hits an edge or middle of the viewport.

sq.trigger(el, {
  when: 'top', // of element
  hits: 'middle', // of viewport
  callback: (el, currentScroll, direction) => {
    console.log('Click!');
  },
});

when can be 'top', 'middle', or 'bottom'. hits can also be 'top', 'middle', or 'bottom', or a number. If it's a number, the callback will fire when the edge/middle of the element has reached that amount of pixels.

  • You can add an offset in px or vh like: 'top+100px', 'middle-50vh', 'bottom-100'.
  • If only an offset is defined, default reference point is top: '+50px', '-10vh'.

Also, instead of when and hits, you can specify an absolute amount of scroll using at:

sq.trigger(el, {
  at: 1000, // px
  callback: (el, currentScroll, direction) => {
    console.log('Click!');
  },
});

Callback is called with the element reference, the current amount of scroll and the direction the user scrolled ('up' or 'down').

By default, the callback will when the mark is passed from any direction. If you want the trigger to be called only when scrolling in one direction, pass direction ('up' or 'down'):

sq.trigger(el, {
  at: 1000, // px
  direction: 'down',
  callback: (el, currentScroll, direction) => {
    console.log('Click!');
  },
});

In this case, if sqroll is started with a document scroll higher than at, the callback will be fired immediately (for example, in a page refresh).

sq.viewport(el, options)

This method will fire one callback every time the element enters the viewport, and one callback everytime it leaves the viewport.

sq.viewport(el, {
  onIn: (el, currentScroll, direction) => {
    console.log('Visible');
  },
  onOut: (el, currentScroll, direction) => {
    console.log('Hidden');
  },
});

Optionally, you can add an offset option with one, or a space-separated pair of offsets (top and bottom), like: offset: '100px 200px.

sq.track(el, options)

This will change a value from a starting point to an ending point while the user scrolls.

sq.track(el, {
  start: {
    when: 'top', // of element
    hits: 'bottom', // of viewport
    value: 0,
  },
  end: {
    when: 'top',
    hits: 'top',
    value: 1,
  },
  callback: (elem, value, scroll, direction) => {
    elem.style.opacity = value;
  },
});
  • start when should the callback start firing, and the initial value. In this example, when the top edge of the element is at the bottom of the viewport, the element opacity will be 0.
  • end when should the callbacks stop, and the final value. In this example, when the top edge of the element is at the top of the viewport, the element opacity will be 1.
  • callback gets called only if value is updated.

You can also use at property instead of when and hits to specify an absolute amount of scroll in one or both start and end objects:

sq.track(el, {
  start: {
    at: 0, // px
    value: 0,
  },
  end: {
    when: 'top',
    hits: 'top',
    value: 1,
  },
  callback: (elem, value, scroll, direction) => {
    elem.style.opacity = value;
  },
});

sq.start()

Start listening to scroll events and firing callbacks.

sq.stop()

Stop listening to scroll events.

sq.clear()

Remove all registered callbacks

sq.destroy()

Stop listening and remove all callbacks.