Skip to content

useScrollParent

A Vue hook to find the nearest scrollable parent element.

Usage

vue
<script setup>
import { ref } from 'vue'
import { useScrollParent } from '@preflower/vue-use'

const el = ref(null)
const scrollParent = useScrollParent(el)
</script>

<template>
  <div ref="el">
    Scroll parent is: {{ scrollParent }}
  </div>
</template>

API

Arguments

NameTypeDescriptionDefault
elRef<Element | null>A Vue Ref to the target element.-
rootScrollElementThe root element to stop searching at.window

Returns

  • A Ref containing the nearest scrollable element (or window).

Released under the ISC License.