Skip to content

BackTop Component ​

This component is used for long pages. After scrolling a certain distance, a back-to-top button appears, making it convenient to quickly return to the top of the page.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage Example ​

html
<template>
    <!-- Global usage -->
    <hy-back-top :scroll-top="scrollTop"></hy-back-top>
</template>

<script lang="ts" setup="">
    import { onPageScroll } from '@dcloudio/uni-app';

    // Create reactive data scrollTop
    const scrollTop = ref(0);

    // Use the onPageScroll method to update the value of scrollTop
    onPageScroll((e) => {
        scrollTop.value = e.scrollTop;
    });
</script>

Changing When the Back-to-Top Button Appears ​

  • You can use the top parameter to change how far the page needs to scroll before the back-to-top button appears
html
<template>
    <hy-back-top :scroll-top="scrollTop" top="600"></hy-back-top>
</template>

Customizing the Back-to-Top Icon and Tooltip ​

  • Use icon to change the icon of the back-to-top button. It can be a built-in icon from the Hy Component Library or an image path
  • Use the text parameter to change the tooltip text of the back-to-top button. If you need to change the color and size of the text, you can use the customStyle parameter
html
<template>
    <hy-back-top :scroll-top="scrollTop" icon="arrow-up" text="Back"></hy-back-top>
</template>

API ​

BackTop Props ​

ParameterDescriptionTypeDefault Value
modeButton shapecircle|squarecircle
iconIcon, see Icon API for detailsstringIconConfig.DOWNLOAD
textTooltip text of the back-to-top buttonstring-
durationTransition duration during the back-to-top process, in msnumber500
scrollTopScroll distance of the pagenumber0
topScroll distance at which the button is displayed, numeric values default to pxnumber|string400
bottomDistance from the back button position to the bottom of the screen, numeric values default to pxnumber|string100
rightDistance from the back button position to the right edge of the screen, numeric values default to pxnumber|string20
z-indexZ-index level of the back-to-top buttonnumber888
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback Parameters
clickButton click-

Slots ​

Slot NameDescriptionAccepted Values
defaultCustom content-

CSS Variables ​

Variable NameDescriptionDefault Value
--hy-back-top-tips-font-sizeTooltip text font size12px
12:33
battery