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:

Example

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

Customized 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>content1</span>
    </div>
  </Scroll>
</template>
<script>
  import { Scroll } from '@empathyco/x-components/scroll';
  export default {
    name: 'ScrollIdTest',
    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>content1</span>
    </div>
  </Scroll>
</template>
<script>
  import { Scroll } from '@empathyco/x-components/scroll';
  export default {
    name: 'ScrollIdTest',
    components: {
      Scroll
    },
    methods: {
      scroll(position) {
        console.log('scroll', position);
      },
      scrollDirectionChange(direction) {
        console.log('scroll:direction-change', direction);
      },
      scrollAtStart(isAtStart) {
        console.log('scroll:at-start', isAtStart);
      },
      scrollAlmostAtEnd(isAlmostAtEnd) {
        console.log('scroll:almost-at-end', isAlmostAtEnd);
      },
      scrollAtEnd(isAtEnd) {
        console.log('scroll:at-end', isAtEnd);
      }
    }
  };
</script>

Using XEvents.

You can use the XEvents subscribing to them.

<template>
  <Scroll throttleMs="50" distanceToBottom="300">
    <div class="content-scroll">
      <span>content1</span>
      <span>content1</span>
    </div>
  </Scroll>
</template>
<script>
  import { Scroll } from '@empathyco/x-components/scroll';
  export default {
    name: 'ScrollIdTest',
    components: {
      Scroll
    },
    mounted() {
      this.$x.on('UserScrolled').subscribe(distance => {
        console.log(distance);
      });
      this.$x.on('UserChangedScrollDirection').subscribe(direction => {
        console.log(direction);
      });
      this.$x.on('UserReachedScrollStart').subscribe(isAtStart => {
        console.log(isAtStart);
      });
      this.$x.on('UserAlmostReachedScrollEnd').subscribe(isAlmostAtEnd => {
        console.log(isAlmostAtEnd);
      });
      this.$x.on('UserReachedScrollEnd').subscribe(isAtEnd => {
        console.log(isAtEnd);
      });
    }
  };
</script>