Skip to content

useWindowScroll

Category
Export Size
2.25 kB
Last Changed
4 weeks ago

Reactive window scroll

Demo

See scroll values in the lower right corner of the screen.
Scroll value
x: 0
y: 0

Usage

vue
<script setup lang="ts">
import { 
useWindowScroll
} from '@vueuse/core'
const {
x
,
y
} =
useWindowScroll
()
</script> <template> <
div
>
read current x, y scroll: {{
x
}}, {{
y
}}
</
div
>
<
button
@
click
="
x
= 100">
scroll X to 100 </
button
>
<
button
@
click
="
y
= 100">
scroll Y to 100 </
button
>
</template>

Type Declarations

ts
export interface UseWindowScrollOptions
  extends ConfigurableWindow, UseScrollOptions {}
export interface UseWindowScrollReturn extends UseScrollReturn {}
/**
 * Reactive window scroll.
 *
 * @see https://vueuse.org/useWindowScroll
 * @param options
 */
export declare function 
useWindowScroll
(
options
?: UseWindowScrollOptions,
): UseWindowScrollReturn

Source

SourceDemoDocs

Contributors

Anthony Fu
Anthony Fu
Nurettin Kaya
Antério Vieira
Vida Xie
青椒肉丝
Robin
Chen
Jelf
webfansplz
Maik Kowol
Shinigami
Alex Kozack

Changelog

v12.3.0 on
a033e - feat: use useScroll under the hood (#4424)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.6.0 on
931b2 - feat: allow rewriting back to scroll (#3500)

Released under the MIT License.

FREE WEEKEND NOW LIVE!
NOW LIVE!
All you can watch! Access ANY course for free
Join now
02
hours
:
33
minutes
:
36
seconds
: