Rooks

useWindowScrollPosition

About

A React hook to get the scroll position of the window

Examples

Basic Usage

import "./styles.css";
import { useWindowScrollPosition } from "rooks";
 
function App() {
  const position = useWindowScrollPosition(); // default config: { wait = 100, passive = true }
  console.log(position); // {x: ..., y: ...}
  return (
    <div style={{ height: 800 }}>
      <h1>Rooks : useWindowScrollPosition Example </h1>
      <br></br>
 
      <p>Scroll </p>
      <p> {JSON.stringify(position)} </p>
    </div>
  );
}
 
export default App;

On this page