1.0.1 • Published 11 months ago

@fcastrovilli/doomscroller v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

DOOMSCROLLER

A simple TypeScript library for detecting and handling scroll and swipe events in web applications.

Features

  • Detects scroll events from mouse wheel, touchpad, and keyboard arrows
  • Handles swipe gestures on touch devices and mouse drag
  • Provides a simple callback interface for scroll direction events
  • Supports vertical and horizontal scrolling/swiping
  • Lightweight and easy to integrate

Installation

pnpm install @fcastrovilli/doomscroller

Usage

Basic Usage

import { createDoomScroller } from "@fcastrovilli/doomscroller";

const removeListeners = createDoomScroller((direction) => {
  console.log(`Scrolled ${direction}`);
});

// When you want to stop listening to events:
removeListeners();

Advanced Usage

import { DoomScroller } from "@fcastrovilli/doomscroller";

const scroller = new DoomScroller((direction) => {
  switch (direction) {
    case "up":
      console.log("Scrolled up");
      break;
    case "down":
      console.log("Scrolled down");
      break;
    case "left":
      console.log("Scrolled left");
      break;
    case "right":
      console.log("Scrolled right");
      break;
  }
});

// When you want to stop listening to events:
scroller.removeEventListeners();

API

createDoomScroller(callback: EventCallback): () => void

Creates a new DoomScroller instance and returns a function to remove the event listeners.

  • callback: A function that receives the scroll direction as a parameter.

class DoomScroller

Constructor: new DoomScroller(callback: EventCallback)

Creates a new DoomScroller instance.

  • callback: A function that receives the scroll direction as a parameter.

Method: removeEventListeners(): void

Removes all event listeners added by the DoomScroller instance.

Types

type ScrollDirection = "up" | "down" | "left" | "right";
type EventCallback = (direction: ScrollDirection) => void;

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

1.0.1

11 months ago

1.0.0

11 months ago

0.0.3

11 months ago