Skip to content

useWindowScroll

Category
Export Size
666 B
Last Changed
3 hours ago

响应式窗口滚动

Demo

查看屏幕右下角的滚动值。
滚动值
x: 0
y: 0

用法

js
import { useWindowScroll } from '@vueuse/core'

const { x, y } = useWindowScroll()
console.log(x.value) // 读取当前的 x 滚动值
y.value = 100 // 将 y 滚动到 100

Type Declarations

typescript
export interface UseWindowScrollOptions
  extends ConfigurableWindow,
    UseScrollOptions {}
/**
 * Reactive window scroll.
 *
 * @see https://vueuse.org/useWindowScroll
 * @param options
 */
export declare function useWindowScroll(options?: UseWindowScrollOptions): {
  x: WritableComputedRef<number, number>
  y: WritableComputedRef<number, number>
  isScrolling: ShallowRef<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>

Source

SourceDemoDocs

Contributors

jorshen

Changelog

No recent changes

Released under the MIT License.