PXD

Scrollable

The container can be scrolled, and the scroll bar or container effect can be customized.

Default

Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque facere ea, hic incidunt necessitatibus.
<template>
  <PScrollable class="w-100 max-w-full h-100 border rounded-md">
    <div class="p-4 w-screen h-screen bg-background-100 rounded-inherit">
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias
      debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque
      facere ea, hic incidunt necessitatibus.
    </div>
  </PScrollable>
</template>

Bottom event

Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque facere ea, hic incidunt necessitatibus.
<script setup>
import { ref } from 'vue'

// The end event will not be triggered repeatedly when loading = true
const isLoading = ref(false)

// Start triggering the end event when it is far from the bottom
const bottomThreshold = 50

let resetLoadingTimer = 0

function onScrollToEnd(dir, ev) {
  console.log('to end, direction: ' + dir)

  clearTimeout(resetLoadingTimer)
  isLoading.value = true
  resetLoadingTimer = setTimeout(() => {
    isLoading.value = false
  }, 1000)
}
</script>

<template>
  <PScrollable
    class="w-100 max-w-full h-100 border rounded-md"
    :loading="isLoading"
    :bottom-threshold="bottomThreshold"
    @bottom="onScrollToEnd"
  >
    <div class="p-4 w-screen h-screen bg-background-100 rounded-inherit">
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias
      debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque
      facere ea, hic incidunt necessitatibus.
    </div>
  </PScrollable>
</template>

Stylize

Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque facere ea, hic incidunt necessitatibus.
<template>
  <PScrollable
    class="w-100 max-w-full h-100 border rounded-md"
    :fader-size="50"
    fader-color="var(--color-blue-300)"
    scrollbar-color="var(--color-orange-400)"
    scrollbar-hover-color="var(--color-orange-600)"
  >
    <div class="p-4 w-screen h-screen bg-background-100 rounded-inherit">
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias
      debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque
      facere ea, hic incidunt necessitatibus.
    </div>
  </PScrollable>
</template>

Just rolling

Hide scroll edges and scroll bars, leaving only the scrolling function.

Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque facere ea, hic incidunt necessitatibus.
<template>
  <PScrollable class="w-100 max-w-full h-100 border rounded-md" :fader="false" :scrollbar="false">
    <div class="p-4 w-screen h-screen bg-background-100 rounded-inherit">
      Lorem ipsum dolor sit amet consectetur adipisicing elit. Amet, cupiditate magnam? Quae alias
      debitis beatae nesciunt veniam excepturi soluta magnam vitae, eius deleniti non doloremque
      facere ea, hic incidunt necessitatibus.
    </div>
  </PScrollable>
</template>

Props

NameTypeDefaultDescription
faderbooleantrueShow gradient faders at the scrollable edges
loadingboolean-Suppress the bottom event while loading more content
scrollbarbooleantrueRender the custom draggable scrollbar instead of the native one
fader-sizenumber-Fader gradient length in px, defaulting to 16
fader-colorstring-Fader gradient color, any CSS color value
fader-direction'horizontal' | 'vertical' | 'both'-Edges to fade: horizontal, vertical or both
wrapper-classstring | any[] | object-Class applied to the outer wrapper element
content-classstring | any[] | object-Class applied to the scrolling content element
content-styleCSSProperties | string-Inline style applied to the scrolling content element
scrollbar-sizenumber-Scrollbar thickness in px, defaulting to 6
scrollbar-colorstring-Thumb color, defaulting to --color-gray-alpha-300
scrollbar-hover-colorstring-Thumb color on hover or active, defaulting to --color-gray-alpha-500
bottom-thresholdnumber10Distance in px from the end that triggers the bottom event

Events

NameTypeDescription
scroll(event: Event) => voidEmitted when the scrollable content is scrolled.
bottom(direction: ComponentDirection, event: Event) => voidEmitted when a vertical or horizontal scroll reaches the end of the content within bottom-threshold.

Slots

NameDescription
defaultDefault slot

Methods

NameTypeDescription
scrollTo(top: number, left: number) => voidScroll the content to the given offsets.
forceUpdate() => voidRecalculate the cached padding and scrollbar metrics immediately.

Source

Source