PerfectScrollbar.vue 824 字节
Newer Older
L
LeoKu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<template>
  <div ref="scrollWrapper" style="position: relative; overflow: hidden">
    <slot />
  </div>
</template>

<script lang="ts" setup>
import PerfectScrollbar from 'perfect-scrollbar'
import { onMounted, onUnmounted, ref } from 'vue'

const props = defineProps<{ options?: PerfectScrollbar.Options }>()

const scrollWrapper = ref<HTMLDivElement>()

let ps: PerfectScrollbar

onMounted(() => {
  if (!scrollWrapper.value) {
    console.warn(`No valid 'PerfectScrollbar' container found`)
    return
  }

  ps = new PerfectScrollbar(scrollWrapper.value, {
    minScrollbarLength: 20,
    maxScrollbarLength: 160,
    ...props.options,
  })
})

onUnmounted(() => {
  ps.destroy()
})
</script>
L
LeoKu 已提交
34 35 36 37 38 39 40 41 42

<style lang="scss">
.ps--active-y .ps__rail-y {
  &:hover,
  &.ps--clicking {
    background-color: #2c323a;
  }
}
</style>