Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scroll-detect-hook

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scroll-detect-hook

This is a hook for React that allows to detect when the window is scrolling and provides you with the direction and position

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

What is it?

It's a hook to be used in React functional components, that allows you to detect when the document is scrolling and in which direction. This is useful to apply custom styling depending on the scrolling state.

The hook returns an array with 3 elements:

  • isScrolling: boolean
  • direction: string, this can be "up", "down" or stopped
  • speed: number, represents the scrolling speed
  • position: number, this is just the Y offset of the document

How to use?

Simply install the module and import the hook:

import useScrollDetector from "scroll-detect-hook";

const Section = () => {
  const { isScrolling, direction, speed, position } = useScrollDetector();
  console.log({ isScrolling, direction, speed, position });
  //   console.log(isScrolling);
  return (
    <div
      style={{
        height: "300vh",
        backgroundColor: isScrolling ? "yellow" : "blue",
      }}
    >
      {isScrolling ? "Yes" : "No"}:{speed}:{direction}
    </div>
  );
};

export default Section;

Coming soon: Listen to scrolling of custom elements

Keywords

FAQs

Package last updated on 15 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc