1 min read

Scroll

Scroll

Scrollable container that emits scroll related X Events. It exposes all the listeners and props from the BaseScroll component.

Props

Name Description Type Default
id Id to identify the component. string MainScrollId

Slots

Name Description Bindings
(name - type - description)
default None

Events

A list of events that the component will emit:

Examples

The Scroll is a component that wraps the BaseScroll and provides it for a unique id.

Basic usage

Overriding the properties

It renders an element with scroll, with the content passed in the default slot.

<template>
  <Scroll id="exampleScrollId" :throttleMs="50" :distanceToBottom="300">
    <div class="content-scroll">
      <span>content1</span>
      <span>content2</span>
    </div>
  </Scroll>
</template>
<script setup>
import { Scroll } from '@empathyco/x-components/scroll'
</script>

Using scroll events.

<template>
  <Scroll
    @scroll="scroll"
    @scroll:direction-change="scrollDirectionChange"
    @scroll:at-start="scrollAtStart"
    @scroll:almost-at-end="scrollAlmostAtEnd"
    @scroll:at-end="scrollAtEnd"
    id="exampleScrollId"
    throttleMs="50"
    distanceToBottom="300"
  >
    <div class="content-scroll">
      <span>content1</span>
      <span>content2</span>
    </div>
  </Scroll>
</template>
<script setup>
import { Scroll } from '@empathyco/x-components/scroll'
function scroll(position) {
  console.log('scroll', position)
}
function scrollDirectionChange(direction) {
  console.log('scroll:direction-change', direction)
}
function scrollAtStart(isAtStart) {
  console.log('scroll:at-start', isAtStart)
}
function scrollAlmostAtEnd(isAlmostAtEnd) {
  console.log('scroll:almost-at-end', isAlmostAtEnd)
}
function scrollAtEnd(isAtEnd) {
  console.log('scroll:at-end', isAtEnd)
}
</script>

Using XEvents

You can use the XEvents API to subscribe to events programmatically:

<template>
  <Scroll throttleMs="50" distanceToBottom="300">
    <div class="content-scroll">
      <span>content1</span>
      <span>content2</span>
    </div>
  </Scroll>
</template>
<script setup>
import { onMounted } from 'vue'
import { Scroll } from '@empathyco/x-components/scroll'
import { use$x } from '../../../composables'
const x = use$x()
onMounted(() => {
  x.on('UserScrolled').subscribe(distance => {
    console.log(distance)
  })
  x.on('UserChangedScrollDirection').subscribe(direction => {
    console.log(direction)
  })
  x.on('UserReachedScrollStart').subscribe(isAtStart => {
    console.log(isAtStart)
  })
  x.on('UserAlmostReachedScrollEnd').subscribe(isAlmostAtEnd => {
    console.log(isAlmostAtEnd)
  })
  x.on('UserReachedScrollEnd').subscribe(isAtEnd => {
    console.log(isAtEnd)
  })
})
</script>