0.0.2 • Published 1 year ago

neuto v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

OptionTypeDefaultDescription
wrapperHTMLElement \| string.neuto-wrapperWrapper element or selector for it
contentHTMLElement \| string.neuto-contentContent element or selector for it
intencitynumber0.1Strength of momentum scrolling
autoUpdateLayoutDebounceWaitnumber200Debounce 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

PropertyTypeDescription
isMomentumScrollingbooleanWhether Momentum scrolling is enabled
isPausedbooleanWhether the scrolling is in paused state or not
scrollYnumberCurrent Scrolling position

Methods

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

Events

Example:

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

License

Licensed under MIT

0.0.2

1 year ago

0.0.1

1 year ago