Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 694 Bytes

File metadata and controls

39 lines (32 loc) · 694 Bytes

useWindowScroll

Vue hook that tracks Window scroll position

Browser environment is required

Usage

import { createComponent } from '@vue/composition-api'
import { useWindowScroll } from 'vuses'

const Demo = createComponent({
  setup() {
    const { x, y } = useWindowScroll()
    return { x, y }
  },
  render() {
    const { x, y } = this
    return (
      <div style={{ width: '200vw', height: '200vh' }}>
        <div style={{ position: 'fixed', top: 10, left: 10 }}>
          <p>x: {x}px</p>
          <p>y: {y}px</p>
        </div>
      </div>
    )
  }
})

Reference

function useWindowScroll(): {
  x: Ref<number>
  y: Ref<number>
}