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

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