neuto
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Neuto

A light weight, zero dependency, simple momentum scrolling library.

Features

  • Keyboard navigation
  • Native scrollbar
  • History back / forward by trackpad or mouse gestures
  • experimental: Find on page (partially supported)
  • Smooth scrolling with custom duration/easing
  • gsap/ScrollTrigger integration

NOTICE: Momentum scrolling is not enabled on touch-only devices.

Installation

npm i neuto

Usage

quick start

<body>
  <div class="neuto-wrapper">
    <div class="neuto-content">
      <!-- contents -->
    </div>
  </div>
</body>
import { Neuto } from 'neuto';

const neuto = new Neuto();

Options

Option Type Default Description
wrapper HTMLElement | string .neuto-wrapper Wrapper element or selector for it
content HTMLElement | string .neuto-content Content element or selector for it
intencity number 0.1 Strength of momentum scrolling
autoUpdateLayoutDebounceWait number 200 Debounce time for updating layout

Using with ScrollTrigger

import gsap from 'gsap';
import ScrollTrigger from 'gsap/ScrollTrigger';
import { Neuto, withScrollTrigger } from 'neuto';

gsap.registerPlugin(ScrollTrigger);

export const neuto = withScrollTrigger(new Neuto({ /* options */ }), ScrollTrigger);

Properties

Property Type Description
isMomentumScrolling boolean Whether Momentum scrolling is enabled
isPaused boolean Whether the scrolling is in paused state or not
scrollY number Current Scrolling position

Methods

Method Description Arguments
scrollTo(destination, options) Scrolls to the specified position. Smooth scrolling by specifying duration as the second argument. destination: number
options: { duration?: number; ease?: (t: number) => number }
paused(isPaused) Pause scrolling. isPaused: boolean
addEventListener(type, callback, options) Subscribe to events. type: string
callback: Function
options: EventListenerOptions (optional)
removeEventListener(type, callback, options) Unsubscribe to events. type: string
callback: Function
options: EventListenerOptions (optional)

Events

Example:

neuto.addEventListener('scroll', ({ detail }) => console.log(`current position: ${detail}`));
Event Description Callback Arguments
scroll Fires on scrolling. detail: number - Current scrolling position

License

Licensed under MIT

Readme

Keywords

none

Package Sidebar

Install

npm i neuto

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

35.4 kB

Total Files

35

Last publish

Collaborators

  • ryohei-endo