Skip to content
本页导读

Backtop 返回顶部

组件类型:UxBacktopComponentPublicInstance

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

平台兼容性

AndroidiOSweb鸿蒙 Next小程序
xx

Slots

名称说明
default默认插槽

Props

属性名类型默认值说明
parentString-父级[scroll-view list-view] id,如果未指定系统会自动查找父级或平级下的[scroll-view list-view]
shapeString'circle'形状
iconString'arrowup'图标
textString'TOP'文字
durationNumber100返回顶部滚动时间
rightNumber30距右距离
bottomNumber100距底距离
iconSizeNumber18图标大小
fontSizeNumber14字体大小
fontBoldBooleanfalse字体加粗
customFontString-网络字体路径 或 自定义字体路径
customFamilyString-字体family
backgroundString'#FFFFFF'背景色
zIndexNumber10000层级z-index
fixedBooleantrue固定定位

shape

属性名说明
circle圆形
square矩形

Events

事件名说明参数
click点击事件MouseEvent

示例代码

html
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll id="testId" @scroll="scroll">
			<ux-card direction="column" icon="flag" title="返回顶部" :bold="true">
				<ux-text text="支持形状、图标、大小、颜色、背景色、插槽等自定义样式"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="返回顶部" text="https://www.uxframe.cn/component/func/backtop.html" mode="link"></ux-text>
				</ux-row>
			</ux-card>
			
			<ux-placeholder :height="1000">
				<ux-row justify="center" :mt="100">
					<ux-text text="上划查看效果"></ux-text>
				</ux-row>
			</ux-placeholder>
			
			<ux-backtop ref="uxBacktopRef1" shape="square" parent="testId" :right="30"></ux-backtop>
			<ux-backtop ref="uxBacktopRef2" icon="up" background="blue" color="white" parent="testId" :right="110"></ux-backtop>
			<ux-backtop ref="uxBacktopRef3" icon="up" text="顶" parent="testId" :right="210"></ux-backtop>
			<ux-backtop ref="uxBacktopRef4" parent="testId" :right="310">
				<ux-text text="顶我"></ux-text>
			</ux-backtop>
		</ux-scroll>
	</ux-page>
</template>
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll id="testId" @scroll="scroll">
			<ux-card direction="column" icon="flag" title="返回顶部" :bold="true">
				<ux-text text="支持形状、图标、大小、颜色、背景色、插槽等自定义样式"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="返回顶部" text="https://www.uxframe.cn/component/func/backtop.html" mode="link"></ux-text>
				</ux-row>
			</ux-card>
			
			<ux-placeholder :height="1000">
				<ux-row justify="center" :mt="100">
					<ux-text text="上划查看效果"></ux-text>
				</ux-row>
			</ux-placeholder>
			
			<ux-backtop ref="uxBacktopRef1" shape="square" parent="testId" :right="30"></ux-backtop>
			<ux-backtop ref="uxBacktopRef2" icon="up" background="blue" color="white" parent="testId" :right="110"></ux-backtop>
			<ux-backtop ref="uxBacktopRef3" icon="up" text="顶" parent="testId" :right="210"></ux-backtop>
			<ux-backtop ref="uxBacktopRef4" parent="testId" :right="310">
				<ux-text text="顶我"></ux-text>
			</ux-backtop>
		</ux-scroll>
	</ux-page>
</template>
ts
<script setup>
	let title = ''
	
	const uxBacktopRef1 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef2 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef3 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef4 = ref<UxBacktopComponentPublicInstance | null>(null)
	
	onLoad((e: OnLoadOptions) => {
		title = 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)
	}
</script>
<script setup>
	let title = ''
	
	const uxBacktopRef1 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef2 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef3 = ref<UxBacktopComponentPublicInstance | null>(null)
	const uxBacktopRef4 = ref<UxBacktopComponentPublicInstance | null>(null)
	
	onLoad((e: OnLoadOptions) => {
		title = 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)
	}
</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>