Skip to content

Scroll Directives

Scroll directives help you manage scroll behavior and infinite loading.

v-scroll

Track scroll position and direction.

Basic Usage

vue
<template>
  <div v-scroll="handleScroll" class="scroll-container">
    Scroll content here
  </div>
</template>

<script setup>
function handleScroll(event, info) {
  console.log('Scroll position:', info.scrollTop)
  console.log('Progress:', info.progressY)
  console.log('Direction:', info.directionY)
}
</script>

Scroll Info Object

The handler receives detailed scroll information:

PropertyTypeDescription
scrollTopnumberCurrent scroll top position
scrollLeftnumberCurrent scroll left position
progressYnumberVertical scroll progress (0-1)
progressXnumberHorizontal scroll progress (0-1)
directionY-1 | 0 | 1Vertical direction (-1: up, 1: down)
directionX-1 | 0 | 1Horizontal direction (-1: left, 1: right)

API

OptionTypeDefaultDescription
handlerFunction-Scroll event handler (required)
throttlenumber0Throttle time in milliseconds
passivebooleantrueUse passive event listener
containerstring | Element-Custom scroll container

v-infinite-scroll

Infinite scroll loading for lists and feeds.

Basic Usage

vue
<template>
  <div v-infinite-scroll="loadMore" class="scroll-container">
    <div v-for="item in items" :key="item.id">
      {{ item.name }}
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const items = ref([...])

async function loadMore() {
  const newItems = await fetchMoreItems()
  items.value.push(...newItems)
}
</script>

API

OptionTypeDefaultDescription
handlerFunction-Handler when scrolling to bottom
distancenumber0Distance from bottom to trigger
disabledbooleanfalseDisable infinite scroll
loadingbooleanfalseLoading state
throttlenumber200Throttle time in milliseconds

v-sticky

Make elements sticky when scrolling.

Basic Usage

vue
<template>
  <div v-sticky>Sticky header</div>
  <div v-sticky="50">Sticky with 50px top offset</div>
  <div v-sticky="{ top: 60, zIndex: 1000 }">Custom sticky</div>
</template>

API

OptionTypeDefaultDescription
topnumber | string0Top offset when sticky
zIndexnumber100Z-index when sticky
stickyClassstring'v-sticky--fixed'CSS class when sticky
onChangeFunction-Callback when sticky state changes

Released under the MIT License.