Skip to content
API 风格:

BackTop ​

Appears after scrolling past a threshold and scrolls back to the top on click, using the native scrollTo({ behavior: 'smooth' }) (degrades automatically under prefers-reduced-motion).

Basic usage ​

Basic (scroll down)
vue
<script setup lang="ts">
</script>

<template>
  <!-- Basic -->
  <LhBackTop :right="24" :bottom="24" />
</template>
vue
<script>
export default {}
</script>

<template>
  <!-- Basic -->
  <LhBackTop :right="24" :bottom="24" />
</template>

visibility-height customizes the threshold, smooth disables smooth scrolling, and target observes a specific scroll container.

Custom threshold, no smooth
vue
<script setup lang="ts">
</script>

<template>
  <!-- Custom threshold, no smooth -->
  <LhBackTop :visibility-height="80" :smooth="false" :right="24" :bottom="90" />
</template>
vue
<script>
export default {}
</script>

<template>
  <!-- Custom threshold, no smooth -->
  <LhBackTop :visibility-height="80" :smooth="false" :right="24" :bottom="90" />
</template>

Scroll end ​

@scrollend fires with the current scroll offset when scrolling stops: the native scrollend event is preferred (Chromium 114+ / Safari 18.2+); older browsers fall back to scroll + a 150ms debounce. Useful for anchor syncing and data lazy-loading.

scrollend event

Last stop: (not scrolled)

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

const lastStop = ref('(not scrolled)')

function onScrollEnd(scrollTop) {
  lastStop.value = `${scrollTop}px`
}
</script>

<template>
  <LhBackTop :right="24" :bottom="160" @scrollend="onScrollEnd" />
</template>
vue
<script>
export default {
  data() {
    return { lastStop: '(not scrolled)' }
  },
  methods: {
    onScrollEnd(scrollTop) {
      this.lastStop = `${scrollTop}px`
    },
  },
}
</script>

<template>
  <LhBackTop :right="24" :bottom="160" @scrollend="onScrollEnd" />
</template>

API ​

LhBackTop Props ​

AttributeDescriptionTypeDefault
targetScroll container (selector or element)string | HTMLElement—
visibilityHeightVisibility threshold in pxnumber200
rightRight offset pxnumber40
bottomBottom offset pxnumber40
smoothSmooth scrollingbooleantrue
sxQuick layout propsLhSxProps—

LhBackTop Events ​

EventDescriptionCallback
clickBack-to-top button clicked; scrolling back starts after the event(e: MouseEvent) => void
scrollendScrolling on the target stops; carries the current scroll offset (native scrollend when supported, scroll + debounce otherwise)(scrollTop: number) => void

Accessibility ​

  • A real <button> named via the backtop.label locale key
  • Hidden state is removed from the tree (v-if)

Type Definitions ​

The TypeScript type structures exported by this component (auto-extracted from packages/components/backtop/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):

LhBackTopProps
ts
export interface LhBackTopProps {
  target?: string | HTMLElement
  visibilityHeight?: number
  right?: number
  bottom?: number
  smooth?: boolean
  sx?: LhSxProps
}

Constants ​

Public constants used by this component (linked from the Type / Default columns in the Props table above):

LH_BACKTOP_VISIBILITY_HEIGHT_DEFAULT (from @lh-ui/share/core/backtop)
ts
export const LH_BACKTOP_VISIBILITY_HEIGHT_DEFAULT = 200
LH_BACKTOP_SCROLLEND_DELAY (from @lh-ui/share/core/backtop)
ts
export const LH_BACKTOP_SCROLLEND_DELAY = 150

Beauty of tradition, foundation of code