Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Global Navigation

  • Navbar
  • BeianFooter
  • Brand
  • AppLauncher
  • Sidebar
  • NavMenu
  • NavigationMenu
  • Menu
  • Menubar
  • Dock
  • BubbleMenu
  • CardNav
  • FlowingMenu
  • GooeyNav
  • PillNav
  • StaggeredMenu

In-page Navigation

  • RouteTabs
  • Tabs
  • Breadcrumb
  • Pagination
  • Anchor
  • Affix
  • BackTop
  • Stepper
  • Steps
  • PageHeader

Actions and Tools

  • Command
  • ContextMenu
  • Toolbar
  • Accordion
  • Collapsible
  • Link
  • AnimatedThemeToggler

BackTop

back-top

Reveals a control that smoothly returns a configured scroll container to the top.

Usage

Basic usage

Monitors window by default. After scrolling beyond visibilityHeight, the back to top button fades into the lower right corner. Click to scroll smoothly back to the top.

Scroll content row 1 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 2 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 3 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 4 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 5 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 6 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 7 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 8 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 9 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 10 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 11 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 12 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 13 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 14 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 15 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 16 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 17 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 18 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 19 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 20 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 21 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 22 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 23 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 24 - scroll down 80px and a back-to-top button appears in the lower right corner.

tsx
<BackTop visibilityHeight={400} />

Custom content

children replaces the default up arrow icon, and can place text or custom nodes.

Scroll content row 1 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 2 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 3 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 4 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 5 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 6 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 7 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 8 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 9 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 10 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 11 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 12 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 13 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 14 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 15 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 16 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 17 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 18 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 19 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 20 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 21 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 22 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 23 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 24 - scroll down 80px and a back-to-top button appears in the lower right corner.

tsx
<BackTop visibilityHeight={400}>
  <span className="px-2 text-xs font-medium">Top</span>
</BackTop>

Specify scroll container

When the page scroll body is not window, target returns the container element, and both monitoring and backing fall on it.

Scroll content row 1 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 2 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 3 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 4 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 5 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 6 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 7 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 8 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 9 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 10 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 11 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 12 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 13 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 14 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 15 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 16 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 17 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 18 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 19 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 20 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 21 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 22 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 23 - scroll down 80px and a back-to-top button appears in the lower right corner.

Scroll content row 24 - scroll down 80px and a back-to-top button appears in the lower right corner.

tsx
const ref = useRef<HTMLDivElement>(null);

<div ref={ref} className="h-44 overflow-y-auto">{/* Long content */}</div>
<BackTop target={() => ref.current} visibilityHeight={80} />

When to use

Use BackTop to reveal a floating button after a long page has scrolled beyond a threshold and return to the top when selected. Use Affix to pin arbitrary content, or Anchor for navigation among page sections.

Import

ts
import { BackTop } from "@hulianui/ui"

Props

NameTypeDefaultDescription
target() => HTMLElement | Window | nullwindowContainer to observe and scroll to the top.
visibilityHeightnumber400Scroll distance in pixels before the button fades in.
classNamestring-The default uses fixed at the viewport's lower-right corner; override with absolute for a local container.
aria-labelstringFollows ConfigProviderAccessible name for the back-to-top action; falls back to the current locale's default wording.

Events

EventTypeDescription
onClick() => voidCalled after the click initiates scrolling.

Slots

SlotTypeDescription
childrenReactNodeCustom floating-button content. Defaults to an upward arrow whose built-in Chinese aria-label is "\u56de\u5230\u9876\u90e8", meaning “Back to top.”

Example

tsx
// Observe window and appear after 400px
<BackTop visibilityHeight={400} />

// Stay inside a local scroll frame
const ref = useRef<HTMLDivElement>(null);
<div className="relative">
  <div ref={ref} className="h-44 overflow-y-auto">{/* Content */}</div>
  <BackTop target={() => ref.current} visibilityHeight={80} className="absolute bottom-3 right-3" />
</div>

Usage guidelines

  • The default fixed positioning targets the full viewport. Inside a local scroller, both pass that element through target and override positioning with className="absolute ..."; otherwise the button sits at the page corner and listens to window instead of the container.
  • Reduced-motion support is built in and changes smooth scrolling to auto; consumers need no extra handling.

Related

The default back-to-top label follows ConfigProvider; pass aria-label to override it.
Tabs · Breadcrumb · Pagination · Anchor · Affix · Stepper

PreviousAffixNavigationNextStepper

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • Usage guidelines
    • Related