Skip to content

BackTop Back-to-Top 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 Compatibility

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 the 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 must 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 Prompt

  • Use icon to change the icon of the back-to-top button; it can be a built-in icon from the Huayue component library, or an image path
  • Use the text parameter to change the text prompt of the back-to-top button. If you need to change the text's color and size, 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
textPrompt text of the back-to-top buttonstring-
durationTransition duration during the return to top, in msnumber500
scrollTopScroll distance of the pagenumber0
topScroll distance required before the button is shown; 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-indexStacking level of the back-to-top buttonnumber888
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events

Event NameDescriptionCallback Parameters
clickTriggered when the button is clicked-

Slots

Slot NameDescriptionAccepted Values
defaultCustom content-
03:29