useScroll 用于创建滚动链接动画,如进度指示器和视差效果。
useScroll
const { scrollYProgress } = useScroll()
<Motion :style="{ scaleX: scrollYProgress }" />
import { useScroll } from 'motion-v'
useScroll 返回四个运动值:
scrollX
Y
scrollXProgress
YProgress
默认情况下,useScroll 跟踪页面滚动。
const { scrollY } = useScroll() useMotionValue(scrollY, 'change', (latest) => { console.log('Page scroll: ', latest) })
例如,我们可以通过将scrollYProgress直接传递给进度条的scaleX样式来显示页面滚动指示器。
scrollYProgress
scaleX
由于 useScroll 返回运动值,我们可以将此滚动信息与其他运动值钩子如 useTransform 和 useSpring 组合:
useTransform
useSpring
On This Page