1.1.0 • Published 6 years ago

react-scroll-sensor v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

react-scroll-sensor

Get the scroll positions of the window object in your component

npm.io

npm npm

Usage

You can use this to build a sticky div which moves around with the cursor.

import ScrollIndicator from "react-scroll-indicator";

<ScrollIndicator throttleDelay={300}>
  {(scrollX, scrollY) => (
    <p
      style={{
        transition: "all 1s ease",
        position: "relative",
        top: `${scrollY}px`,
        flex: "0 0 200px"
      }}
    >
      Hello
    </p>
  )}
</ScrollIndicator>;

Props

PropDescriptionTypeValues
throttleDelayThe time in milliseconds in which to throttle the event.Numberdefault 300

Render props

Render propDescriptionTypeValues
scrollXwindow.scrollX renderedNumber0
scrollYwindow.scrollYNumber0
mountedWhether react-scroll-sensor has already mounted. If it's not, then it's the first render and scroll positions are 0Booleantrue/false

Enjoy 🎆