All Projects → AndrzejSala → use-scroll-direction

AndrzejSala / use-scroll-direction

Licence: MIT license
A simple, performant, and cross-browser hook for detecting scroll direction in your next react app.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to use-scroll-direction

use-smooth-scroll
React hook which gives a smooth scrolling function.
Stars: ✭ 41 (+70.83%)
Mutual labels:  hooks, hook, scroll
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (+11104.17%)
Mutual labels:  hooks, hook, scrolling
window-scroll-position
React hook for Window scroll position
Stars: ✭ 81 (+237.5%)
Mutual labels:  hook, scroll, window
react-smart-scroll
Efficient rendering of long lists in React
Stars: ✭ 27 (+12.5%)
Mutual labels:  scrolling, scroll
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (+170.83%)
Mutual labels:  hooks, custom-hook
onscroll-effect
A tiny JavaScript library to enable CSS animations when user scrolls.
Stars: ✭ 35 (+45.83%)
Mutual labels:  scrolling, scroll
react-ui-hooks
🧩Simple repository of React hooks for building UI components
Stars: ✭ 20 (-16.67%)
Mutual labels:  hooks, hook
crypto-watchdog
Crypto Watchdog is an open-source developer friendly project, periodically queries crypto market and notifies potential pumps & recently added tokens/coins via web-hooks.
Stars: ✭ 22 (-8.33%)
Mutual labels:  hooks, hook
use-gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 6,624 (+27500%)
Mutual labels:  hooks, scroll
react-use-hoverintent
React hook for hoverIntent
Stars: ✭ 16 (-33.33%)
Mutual labels:  hooks, hook
really-smooth-scroll
A script that smoothen scrolling in the browser
Stars: ✭ 21 (-12.5%)
Mutual labels:  scrolling, scroll
use-double-tap
React hook for handling double tap on mobile devices
Stars: ✭ 18 (-25%)
Mutual labels:  hooks, hook
react-scroll-trigger
📜 React component that monitors scroll events to trigger callbacks when it enters, exits and progresses through the viewport. All callback include the progress and velocity of the scrolling, in the event you want to manipulate stuff based on those values.
Stars: ✭ 126 (+425%)
Mutual labels:  scrolling, scroll
scroll-sync-react
A scroll syncing library for react that is up to date
Stars: ✭ 49 (+104.17%)
Mutual labels:  scrolling, scroll
NoobScroll
A lightweight jQuery Plugin that add some cool function to make scrolling more fun [Archive]
Stars: ✭ 43 (+79.17%)
Mutual labels:  scrolling, scroll
react-is-scrolling
Simply detect if users are scrolling in your components in a declarative API
Stars: ✭ 17 (-29.17%)
Mutual labels:  scrolling, scroll
React Native Swiper Flatlist
👆 Swiper component implemented with FlatList using Hooks & Typescript + strict automation tests with Detox
Stars: ✭ 217 (+804.17%)
Mutual labels:  hooks, scroll
flhooks
React like Hooks implementation for Flutter.
Stars: ✭ 38 (+58.33%)
Mutual labels:  hooks, custom-hook
Fre
👻 Tiny Footprint Concurrent UI library for Fiber.
Stars: ✭ 3,195 (+13212.5%)
Mutual labels:  hooks, hook
Masonic
🧱 High-performance masonry layouts for React
Stars: ✭ 209 (+770.83%)
Mutual labels:  hooks, window

use-scroll-direction

Latest Stable Version CI Status Codecov Gzipped size License

A simple, performant, and cross-browser hook for detecting scroll direction in your next react app.

Key Features

  • Performant 🔥
    Do what is only needed. In a good way.
    Use passive listener and throttling to make it invesible for your device.

  • Versatile 💪🏼
    Handle both X & Y axis, on browser window or custom element (ref). Need more quick/lazy response? Play with wait option.

  • Microlight 🪶
    It's lighter than the air, only ~1.6kB.

  • Cross-everything 🖥️
    The same behavior on all kind of browsers and devices. No excuces (even on Iphone Safari).

  • Great support 👨🏻
    Stuck with implementation or has interesting use case and need something more? Create an issue and share your voice.

Installation

npm i use-scroll-direction

Usage

The hook returns the object with the actual scroll direction which could be one of three states: 'NONE', 'DOWN', 'UP', 'LEFT', 'RIGHT' and useful booleans.

Use on window object

import {useScrollDirection} from "use-scroll-direction";

export const WindowExample = () => {
    const {
        scrollDirection,
        isScrolling,
        isScrollingUp,
        isScrollingDown,
        isScrollingLeft,
        isScrollingRight
    } = useScrollDirection();

    useEffect(() => {
        console.log(scrollDirection)
    }, [scrollDirection]);

    return (
      <div>{...}</div>
    )
};

Use on the specific element

import {useScrollDirection} from "use-scroll-direction";

export const ComponentRefExample = () => {
    const elementRef = useRef(null);
    const {scrollDirection} = useScrollDirection({ref: elementRef});

    useEffect(() => {
        console.log(scrollDirection)
    }, [scrollDirection]);

    return (
        //The content needs to overflow a container
        <div ref={elementRef} style={{height: '100vh', overflowY: 'scroll'}} >
            <div>{...}</div>
        </div>
    )
};

Available options

Name Type Description
wait ?number Time in ms for throttling of scroll handler (default: 50)
timeToReset ?number Time in ms after last scroll event to reset the state (default: 150)
ref ?HTMLElement When passed, the listener will be attached to element instead of window object
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].