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

av-scroll

v0.0.2

Published

Smooth scrolling paired with horizontal scroll.

Downloads

3

Readme

AV scroll

Smooth scrolling paired with horizontal scroll.

Overview

ALPHA version ⚠️ Still In Development: works on mobile, works on desktop. Don't try to rescale from mobile to desktop or vice-versa.

npm install av-scroll

Basic

CSS

Add the base styles to your CSS file.

avscroll.css

JS

When calling new AvScroll, you have to add an object that contains: elements.wrapper, lerp, links. An example can be found below. All other methods are optional.

import AvScroll from 'AvScroll';

new AvScroll({
  elements: {
    wrapper: document.querySelector('.page__container');,
  },
  lerp: {
    default: 0.1,
    modified: 0.04,
  },
  links: {
    default: true,
  },
});

Adding Horizontal Scrolling

First, you need to create your horizontal section, and add content to it. Make sure that the section is wide enough.

Make sure that there's some spacing between two horizontal sections. Adding two horizontal sections in a row might cause bugs, but you can experiment with it.

Use the threshold to trigger adjust the time section gets inFocus. Threshold of 1 is your entire viewport, 0.5 half of the viewport. Like in the intersectionObserver.

There are two options to add horizontal scroll.

1. On initialization

Simply paste the horizontal object like in the example below:

new AvScroll({
  elements: {
    wrapper: document.querySelector('.page__container');,
  },
  horizontal: ['.gallery', '.gallery2'],
  lerp: {
    default: 0.1,
    modified: 0.04,
  },
  links: {
    default: true,
  },
});

You can add strings '.gallery' or paste already selected div (with document.querySelector or whatever)

2. Via function

Call the addHorizontal() function on the AvScroll instance. It will add instance. This method there in case you want to make this dynamic. It will recalculate the total height and everything automatically.

const avScroll = new AvScroll({...});

avScroll.addHorizontal('.gallery');

Commands

debug mode

Enables debug window where scroll progress, inFocus, breakpoints, and other features can be tracked. Enabling debug mode, also enables the console log.

const avScroll = new AvScroll({
  elements: {
    wrapper: document.querySelector('.page__container');,
  debug: true,
  ...
});

lerp

The amount of linear interpolation. The smaller the value, the smoother it scrolls.

const avScroll = new AvScroll({
	elements: {
    wrapper: document.querySelector('.page__container');,
  },
	lerp: {
    default: 0.1,
    modified: 0.04,
  },
	...
});

default - used on scroll
modified - use when clicking links

links

If default: true - adds ALL 'a' tag elements on your entire website. If you want to control what gets selected, you can specify an array of links instead.

const avScroll = new AvScroll({
  elements: {
    wrapper: document.querySelector('.page__container');,
  },
  links: {
    // default: true, // default value
    default: [
      document.querySelectorAll('.vgallery a')[0],
      document.getElementById('link2hor'),
      document.getElementById('link2last'),
    ],
  },
  ...
});

mobile breakpoints

I suggest disabling the scroller on mobile, otherwise, it will cause lag on weak devices. You can do that by specifying the breakpoint. Default breakpoint is set to 768px.

To keep smooth scroll on mobile, set the breakpoint to 0.

ALPHA 0.0.2-a ⚠️ as of now, rescaling the window in the browser from desktop to mobile can cause some issues. Either keep breakpoint at 0, or hope that your site visitor won't begin rescaling it weirdly.

const avScroll = new AvScroll({
  elements: {
    wrapper: document.querySelector('.page__container');,
  },
  mobile: {
    breakpoint: 768,
  },
  ...
});

Examples for all commands

new AvScroll({
  elements: {
    wrapper: document.querySelector('.content__wrapper'),
  },
  horizontal: ['.gallery', '.gallery2'],
  mobile: {
    breakpoint: 768,
  },
  threshold: 1,
  debug: false,
  lerp: {
    default: 0.1,
    modified: 0.04,
  },
  links: {
    default: true, // picks all 'a' elements
    // picks an array with elements (querySelector or getElementById!)
		// default: [
    //   document.querySelectorAll('.vgallery a')[0],
    //   document.getElementById('link2hor'),
    //   document.getElementById('link2last'),
    // ],
  },
});

GSAP

GSAP ScrollerProxy

The scrollProxy is already added to the package and is done automatically, meaning that it works with GSAP Scroll Trigger out of the box. Just make sure to put avScroll before any GSAP tweens.

Update History

2023-01-15 | 0.0.1-a initial release 2023-02-09 | 0.0.2-a horizontal scrolling, basic mobile breakpoints, touch support, bug fixes

Misc

Follow Averyano: Twitter, GitHub, Instagram

License

MIT

by Averyano