useWindowScroll
响应式窗口滚动
示例
查看屏幕右下角的滚动值。
滚动值
x: 0y: 0
用法
js
import { useWindowScroll } from '@vueuse/core'
const { x, y } = useWindowScroll()
console.log(x.value) // 读取当前的 x 滚动值
y.value = 100 // 将 y 滚动到 100
类型声明
typescript
export interface UseWindowScrollOptions
extends ConfigurableWindow,
UseScrollOptions {}
/**
* 响应式窗口滚动。
*
* @see https://vueuse.org/useWindowScroll
* @param options
*/
export declare function useWindowScroll(options?: UseWindowScrollOptions): {
x: WritableComputedRef<number, number>
y: WritableComputedRef<number, number>
isScrolling: Ref<boolean, boolean>
arrivedState: {
left: boolean
right: boolean
top: boolean
bottom: boolean
}
directions: {
left: boolean
right: boolean
top: boolean
bottom: boolean
}
measure(): void
}
export type UseWindowScrollReturn = ReturnType<typeof useWindowScroll>
源码
贡献者
Anthony Fu
一纸忘忧
Nurettin Kaya
Antério Vieira
Robin
Anthony Fu
Chen
Jelf
webfansplz
Maik Kowol
Shinigami
Alex Kozack