useWindowScroll
useWindowScroll 是一个 React Hook,它用于获取浏览器窗口的滚动位置
Usage
实时编辑器
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> ); };
结果
Loading...
API
useWindowScroll
Returns
UseWindowScrollState
Arguments
useWindowScrollState
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
x | 水平滚动的像素值 | number (必填) | - |
y | 垂直滚动的像素值 | number (必填) | - |