You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
416 B

2 years ago
  1. import { useState } from 'react'
  2. export function useWindowScroll () {
  3. const [y, sety] = useState(0)
  4. // 在滚动行为发生的时候,不断获取滚动值,然后交给 y
  5. window.addEventListener('scroll', () => {
  6. const h = document.documentElement.scrollTop // documentElement 属性以一个元素对象返回一个文档的文档元素。
  7. sety(h)
  8. })
  9. return [y]
  10. }