Skip to content
本页导读

Backtop

组件类型:UxBacktopComponentPublicInstance

支持形状、图标、大小、颜色、背景色、插槽等自定义样式

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
defaultSlot默认插槽
parentString父级[scroll-viewlist-view]id,如果未指定系统会自动查找父级或平级下的[scroll-viewlist-view]
shapeStringcircle形状
iconStringarrowup图标
textStringTOP文字
durationNumber100返回顶部滚动时间
rightAny30距右距离
bottomAny100距底距离
iconSizeAny18图标大小
fontSizeAny14字体大小
fontBoldBooleanfalse字体加粗
customFontString网络字体路径或自定义字体路径
customFamilyString字体family
backgroundString#FFFFFF背景色
zIndexNumber10000层级z-index
fixedBooleantrue固定定位

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>