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

@studio206/fortis

v0.1.2

Published

Fortis is a smooth scroll library to normalize the scrolling experience across devices

Downloads

7

Readme

LENIS

Introduction

🚧 Still in WIP, API might change with new releases 🚧

This is our take on smooth scroll, lightweight, hard working, smooth as butter scroll. See Demo

Features

  • Performant
  • Lightweight (~2Kb gzipped)
  • Run scroll in main thread
  • Accessibility (CMD+F page search, keyboard navigation, keep scroll position on page refresh, etc.)
  • External RAF
  • SSR proof
  • Not opinionated
  • Tree-shakeable
  • Custom scroll easing/duration

| Feature | Locomotive-scroll | GSAP ScrollSmoother | Lenis | |-----------------------------|-------------------|---------------------|--------| | Native scrollbar | ❌ | ✅ | ✅ | | Native scroll inputs | ❌ | ✅ | ❌ | | Normalize scroll experience | ✅ | ❌ | ✅ | | Accessibility | ❌ | ❌ | ✅ | | CSS Sticky | ❌ | ❌ | ✅ | | IntsersectionObserver | ❌ | ❌ | ✅ | | Open source | ✅ | ❌ | ✅ | | Built-in animation system | ✅ | ✅ | ❌ | | Size (gzip) | 12.33KB | 26.08KB | 2.13kb |

Installing

using package manager:

$ npm i @studio-freight/lenis

using scripts:

<script src="https://cdn.jsdelivr.net/gh/studio-freight/lenis@latest/bundled/lenis.js"></script>

Setup

Basic setup

import Lenis from '@studio-freight/lenis'

const lenis = new Lenis({
  duration: 1.2,
  easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
  direction: 'vertical', // vertical, horizontal
  gestureDirection: 'vertical', // vertical, horizontal, both
  smooth: true,
  mouseMultiplier: 1,
  smoothTouch: false,
  touchMultiplier: 2,
  infinite: false,
})

//get scroll value
lenis.on('scroll', ({ scroll, limit, velocity, direction, progress }) => {
  console.log({ scroll, limit, velocity, direction, progress })
})

function raf(time) {
  lenis.raf(time)
  requestAnimationFrame(raf)
}

requestAnimationFrame(raf)

Using custom scroll container

const lenis = new Lenis({
  wrapper: NodeElement, // element which has overflow
  content: NodeElement, // usually wrapper's direct child
})

Instance settings

| Option | Type | Default | Description | | ------------------ | ------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | | wrapper | NodeElement | window | Default element which has overflow | | content | NodeElement | document | wrapper's direct child | | duration | number | 1.2 | Specifies the duration of the animation | | easing | function | (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)) | Specifies the rate of change of a specific value, our default is custom but you can pick one from Easings.net | | direction | string | vertical | vertical or horizontal scrolling. | | gestureDirection | string | vertical | vertical, horizontal or both. | | smooth | boolean | true | Enable or disable 'smoothness' | | mouseMultiplier | number | 1 | This value is passed directly to Virtual Scroll | | smoothTouch | boolean | false | Enable or disable 'smoothness' while scrolling using touch. Note: We have disabled it by default because touch devices native smoothness is impossible to mimic | | touchMultiplier | number | string | This value is passed directly to Virtual Scroll | | infinite | boolean | false | Enable infinite scrolling! |

Methods

  • raf(time) : must be called every frame for internal function.
  • scrollTo(target, {offset, duration, easing, immediate}) : scroll to a target.
    • target : can be Number, NodeElement or String (CSS selector).
    • offset : Number equivalent to scroll-padding-top.
    • duration : Number scroll duration in seconds.
    • easing : Function.
    • immediate : ignore duration and easing.
  • on(id, callback) : execute a function on event.
    • id : event to listen.
      • scroll : return scroll position.
    • callback(e) : function to execute.
  • stop() : pause the scroll
  • start() : resume the scroll
  • destroy() : destroy the instance, remove all events.

Considerations

Things to consider if you want to add Lenis to your codebase will be listed here.

Make sure scroll-behavior is set to initial or not set at all (thanks @thagxt)

html {
  scroll-behavior: initial;
}

Keep html and body elements default sized (see this issue)

html,
body {
  width: 100%;
  min-height: 100%;
}

Stop wheel event propagation on elements with overflow (see this issue)

<div onwheel="event.stopPropagation()">scroll content</div>

Manually use lenis.scrollTo('#anchor') on anchor link click (see this issue)

<a href="#anchor" onclick="lenis.scrollTo('#anchor')">scroll to anchor</a>

Plugins

Lenis in use

Authors

This set of hooks is curated and maintained by the Studio Freight Darkroom team:

License

The MIT License.