Skip to content

BackTop - Vant 4

BackTop

🚀 Ready to give your users a smooth ride back to the top? Let's explore the BackTop component!

Intro 📖

A sleek and handy button that helps users effortlessly return to the top of the page! 🔝 Perfect for long content pages where scrolling back up manually would be a real workout for your thumb! 💪

Install 📦

Get started in seconds! Register the component globally via app.use - it's that simple! 🎯 Check out our Component Registration guide for more installation options.

js
import { createApp } from'vue'; import { BackTop } from'vant'; const app = createApp(); app.use(BackTop);

Usage 🎮

Basic Usage ⚡

Time for some magic! Scroll down on the demo page and watch the back-to-top button appear like a helpful genie! 🧞‍♂️

html
js
exportdefault { setup() { const list = [...Array(50).keys()]; return { list }; }, };

Custom Position 📍

Want to move things around? Use the right and bottom props to position your BackTop button exactly where you want it! 🎯 It's like interior decorating for your UI!

html
js
exportdefault { setup() { const list = [...Array(50).keys()]; return { list }; }, };

Custom Content 🎨

Feeling creative? Use the default slot to customize your button content! 🖌️ Make it uniquely yours with custom icons, text, or whatever your heart desires!

html
js
exportdefault { setup() { const list = [...Array(50).keys()]; return { list }; }, };

Set Scroll Target 🎯

html
js
exportdefault { setup() { const list = [...Array(50).keys()]; return { list }; }, };

Immediate Scroll ⚡

Need speed? Add the immediate prop to scroll to the top instantly - no smooth animation, just pure velocity! 🚀 Perfect for when your users are in a hurry!

html

API

Props

AttributeDescriptionTypeDefault
targetCan be a selector or a DOM ELement, default closest parent scrolling container*stringHTMLElement*
rightRight distance of the page, the default unit is px*numberstring*
bottomBottom distance of the page, the default unit is px*numberstring*
offsetThe component will not display until the scroll offset reaches this valuenumber200
teleportSpecifies a target element where BackTop will be mounted*stringElement*
immediate v4.0.9Whether to scroll to top immediatelybooleanfalse
z-indexSet the z-index to a fixed value*numberstring*

Events

EventDescriptionArguments
clickEmitted when Component is clickedevent: MouseEvent

Slots

NameDescription
defaultcustomize default content

Types

The component exports the following type definitions:

ts
importtype { BackTopProps, BackTopThemeVars } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-back-top-size40px-
--van-back-top-icon-size20px-
--van-back-top-right30px-
--van-back-top-bottom40px-
--van-back-top-z-index100-
--van-back-top-text-color#fff-

| --van-back-top-background | var(--van-blue) | - |

  • Button - Interactive button component
  • Icon - Icon component for custom content

Enterprise-level mobile solution based on Vant