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

af-scroll

v1.1.1

Published

Animation Frame Scroll

Downloads

1

Readme

AFScroll (Animation Frame Scroll)

The script aligns page scroll update with animation frame.
It allows to perform js based DOM manipulation related to page scroll just in time, not too late.

Demo

Menu

Quick start

Install

# install af-scroll npm package
npm install --save af-scroll

Initialization

// import create function
import createAFScroll from 'af-scroll';

// call to initialize
createAFScroll();

Imports

The library build is delivered in two formats: esmodule and commonjs

// default import (esmodule)
import createAFScroll from 'af-scroll';

// explicit import (esmodule)
import createAFScroll from 'af-scroll/dist/esmodule';

// explicit import (commonjs)
const createAFScroll = require('af-scroll/dist/commonjs');

Features

  • alignment of js on scroll updates with the visual scroll update
  • on scroll updates throttled by requestAnimationFrame
  • native scroll triggers (native scrollbar, mouse wheel, keyboard, touch)
  • scroll smoothing (optional)
  • scroll locking (optional)

Disadvantages

  • additional wrapping element in DOM
  • missing support for native scroll to results of find on page

Why you may need AFScroll?

If you want to manipulate DOM elements by js and set them based on the scroll position.

What happens when you use default scroll:

  • user scrolls a page
  • browser renders new scroll position
  • user sees new scroll position
  • the native on scroll event is triggered
  • js updates for current scroll position
    (any custom DOM manipulations by js)
  • user sees DOM elements updated by js

What happens when you use AFScroll:

  • user scrolls a page
  • browser renders new scroll position
  • user not sees new scroll position
  • the native on scroll event is triggered
  • js updates for current scroll position
    (update visible scroll position & any custom DOM manipulations by js)
  • user sees new scroll position & DOM elements updated by js in the same time

Options

createAFScroll({
  smoothForce: 0.8,
  smoothLimit: 0.2,
  scrollEl: null,
  className: 'afScroll',
  wrapExclude: 'script, link',
  autoHeight: 12,
  onUpdate: () => {},
  onComplete: () => {},
});

| Option | Type | Default | Description | | --- | --- | --- | --- | | smoothForce | Number | 0.8 | smoothing force in range 0.0 - 1.00: no smooth1: no scroll | | smoothLimit | Number | 0.2 | min diff between current and target value to keep smooth loop | | scrollEl | Element | null | static scroll wrapper element1 | | className | String | "afScroll" | css class name of scroll wrapper element2 | | wrapExclude | String | "script, link" | css selector to exclude from wrapping2 | | autoHeight | Number | 12 | height checking period in frames1: each frame0: disabled12: once per each 12 frames | | onUpdate | Function | () => {} | callback function triggered on scroll update | | onComplete | Function | () => {} | callback function triggered after smooth loop stopped |

  1. prevents DOM modification by auto created wrapper, passed scrollEl will be used instead of it
  2. ignored if scrollEl passed

Methods

// example of using methods
const afScroll = createAFScroll(/* optional options */);
afScroll.scrollTo(0); // scroll to top
afScroll.scrollTo(0, true); // scroll to top forced
afScroll.free(); // free forced scroll
afScroll.lock(); // lock scroll
afScroll.unlock(); // unlock scroll
afScroll.destroy(); // destroy af-scroll
afScroll.init(); // reinit af-scroll

| Method | Arguments | Return | Description | | --- | --- | --- | --- | | init() | none | undefined | reinitialize the script after destroy | | scrollTo(scroll, force) | scroll {Number} target scroll value in px unitforce {Boolean} prevents user from changing a scroll target until it completes | undefined | scroll to scroll value | | free() | none | undefined | free forced scroll | | lock() | none | undefined | lock scroll | | unlock() | none | undefined | unlock scroll | | destroy() | none | undefined | destroy the script and restore original html |

Events

createAFScroll({
  onUpdate: (scroll) => {
    // custom behavior
  },
  onComplete: (scroll) => {
    // custom behavior
  },
});

| Event | Arguments | When triggered | | --- | --- | --- | | onUpdate(scroll) | scroll {Number} scroll value in px unit | in each animation frame of move to target scroll | | onComplete(scroll) | scroll {Number} scroll value in px unit | after achieve target scroll - smooth loop stopped |