Skip to main content

useWindowScroll

useWindowScroll is a React Hook that is used to get the scroll position of the browser window

Usage

Live Editor
function Demo() {
  return (
    <div>
      <div>
        <iframe
          src="https://codesandbox.io/embed/dreamy-lehmann-mzg96r?fontsize=14&hidenavigation=1&theme=dark"
          style={{
            width: "100%",
            height: 500,
            border: 0,
            borderRadius: 4,
            overflow: "hidden",
          }}
          title="dreamy-lehmann-mzg96r"
          allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
          sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
        >
        </iframe>
      </div>
    </div>
  );
};

Result
Loading...

API

useWindowScroll

Returns

UseWindowScrollState

Arguments

useWindowScrollState

PropertyDescriptionTypeDefaultValue
xpixel value of horizontal scrollingnumber (Required)-
ypixel value of vertical scrollingnumber (Required)-