Backtop
组件类型:UxBacktopComponentPublicInstance
支持形状、图标、大小、颜色、背景色、插槽等自定义样式
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
default | Slot | 默认插槽 | |
parent | String | 父级[scroll-viewlist-view]id,如果未指定系统会自动查找父级或平级下的[scroll-viewlist-view] | |
shape | String | circle | 形状 |
icon | String | arrowup | 图标 |
text | String | TOP | 文字 |
duration | Number | 100 | 返回顶部滚动时间 |
right | Any | 30 | 距右距离 |
bottom | Any | 100 | 距底距离 |
iconSize | Any | 18 | 图标大小 |
fontSize | Any | 14 | 字体大小 |
fontBold | Boolean | false | 字体加粗 |
customFont | String | 网络字体路径或自定义字体路径 | |
customFamily | String | 字体family | |
background | String | #FFFFFF | 背景色 |
zIndex | Number | 10000 | 层级z-index |
fixed | Boolean | true | 固定定位 |
shape
值 | 说明 |
---|---|
circle圆形 | |
square矩形 |
Events
事件名 | 说明 | 参数 |
---|---|---|
click | 点击按钮时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll :scroll-top="scrollTop" @scroll="scroll">
<ux-card direction="column" icon="flag-filled" title="返回顶部" :bold="true">
<ux-text text="支持形状、图标、大小、颜色、背景色、插槽等自定义样式"></ux-text>
</ux-card>
<ux-placeholder :height="1000">
<ux-row justify="center" :mt="100">
<ux-text text="上划查看效果"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
<view>
<ux-backtop ref="uxBacktopRef1" shape="square" :right="30" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef2" icon="to-top" text="" :background="primaryColor" color="white" :right="110" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef3" icon="arrow-top" :right="210" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef4" :right="310" @click="toTop">
<ux-text text="顶我"></ux-text>
</ux-backtop>
</view>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll :scroll-top="scrollTop" @scroll="scroll">
<ux-card direction="column" icon="flag-filled" title="返回顶部" :bold="true">
<ux-text text="支持形状、图标、大小、颜色、背景色、插槽等自定义样式"></ux-text>
</ux-card>
<ux-placeholder :height="1000">
<ux-row justify="center" :mt="100">
<ux-text text="上划查看效果"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
<view>
<ux-backtop ref="uxBacktopRef1" shape="square" :right="30" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef2" icon="to-top" text="" :background="primaryColor" color="white" :right="110" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef3" icon="arrow-top" :right="210" @click="toTop"></ux-backtop>
<ux-backtop ref="uxBacktopRef4" :right="310" @click="toTop">
<ux-text text="顶我"></ux-text>
</ux-backtop>
</view>
</template>
ts
<script setup>
import { useThemeColor } from '@/uni_modules/ux-frame'
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const scrollTop = ref(0)
const uxBacktopRef1 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef2 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef3 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef4 = ref<UxBacktopComponentPublicInstance | null>(null)
const primaryColor = computed(() => {
return useThemeColor('primary')
})
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/backtop.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function scroll(e: ScrollEvent) {
let show = e.detail.scrollTop > 100
uxBacktopRef1.value?.$callMethod('setShow', show)
uxBacktopRef2.value?.$callMethod('setShow', show)
uxBacktopRef3.value?.$callMethod('setShow', show)
uxBacktopRef4.value?.$callMethod('setShow', show)
}
function toTop() {
scrollTop.value = -1
nextTick(() => {
scrollTop.value = 0
})
}
</script>
<script setup>
import { useThemeColor } from '@/uni_modules/ux-frame'
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const scrollTop = ref(0)
const uxBacktopRef1 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef2 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef3 = ref<UxBacktopComponentPublicInstance | null>(null)
const uxBacktopRef4 = ref<UxBacktopComponentPublicInstance | null>(null)
const primaryColor = computed(() => {
return useThemeColor('primary')
})
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/backtop.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function scroll(e: ScrollEvent) {
let show = e.detail.scrollTop > 100
uxBacktopRef1.value?.$callMethod('setShow', show)
uxBacktopRef2.value?.$callMethod('setShow', show)
uxBacktopRef3.value?.$callMethod('setShow', show)
uxBacktopRef4.value?.$callMethod('setShow', show)
}
function toTop() {
scrollTop.value = -1
nextTick(() => {
scrollTop.value = 0
})
}
</script>
css
<style lang="scss">
.b1 {
background-color: blue;
width: 100%;
height: 300px;
display: flex;
}
.b2 {
background-color: red;
width: 100%;
height: 300px;
}
.b3 {
background-color: black;
width: 100%;
height: 300px;
}
.b4 {
background-color: green;
width: 100%;
height: 300px;
}
</style>
<style lang="scss">
.b1 {
background-color: blue;
width: 100%;
height: 300px;
display: flex;
}
.b2 {
background-color: red;
width: 100%;
height: 300px;
}
.b3 {
background-color: black;
width: 100%;
height: 300px;
}
.b4 {
background-color: green;
width: 100%;
height: 300px;
}
</style>