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

mouse-scroll-smoothing

v0.1.7

Published

Smooth scrolling based on native browser scrollbar

Downloads

15

Readme

Mouse Scroll Smoothing

Lightweight vanilla smooth scrolling based on native browser scrollbar.

It intends to smooth mouse scrolling, but immediatly cancels easing if user switches to a trackpad or drags on a touch screen (hybrid devices scenario).

Implementing this on a touch only device is not recommanded. You should use a detection library such as detect-it.

Installation

npm i mouse-scroll-smoothing --save

Implementation

import SmoothScroll from 'mouse-scroll-smoothing';

const smoothScroll = new SmoothScroll(domElement, options);

Run npm i && npm start to build the demo.

Documentation

Constructor

SmoothScroll(domElement, options)

  • domElement is the translated DOM.
  • options is an object of options:
    options.easing [0,1]: easing applied on scroll (every browsers but Firefox).
    options.easingFf [0,1]: easing applied on scroll (Firefox only).
    options.autoResize: automatically adds a resize event on window. Set if to false if you already have a listener and want to manually call resize method.
    options.autoRaf: automatically calls update method on requestAnimationFrame. Set if to false if you already have a RAF running and call update method manually.
    options.rafCallback: if options.autoRaf is set to true, setting a RAF callback can be useful for animation purposes. The callback with return scroll percent as first param. options.disablePointerEvents: disable pointer events (set to none) while scrolling (default is true).

Public methods

resize(wh)

This method has to be called on window resize event if options.autoResize is false, or anytime you update the domElementcontent.

  • wh is the window height. Defaults to window.innerHeight. You can use a cached value to limit reflow.

Consider debouncing resize call to limit DOM reflow.

update(now)

This method has to be called on RAF (called automatically if options.autoRaf is true).

  • now is a boolean, set it to true to force an update without easing.

destroy()

Removes listeners.

Getters & setters

enabled = [true|false]

Set enabled to false to disable scrolling, true to enable it.

percent (read only)

Returns the scroll position in percent. Useful to animate a timeline proportionally to scroll on RAF update.