<template>
<view v-show="show" class="totop" :style="{bottom: bottom + ‘rpx‘}">
<view class="totop_content" @click="toTop">
<view class="img_wrapper">
<image :src="topIcon" />
</view>
<text>顶部</text>
</view>
</view>
</template>
<script>
export default {
props: {
scrollTop: {
type: Number,
default: 0
},
bottom: {
type: Number,
default: 40
}
},
data() {
return {
topIcon: ‘/static/icon/toTop.svg‘
}
},
computed: {
show() {
let show = this.scrollTop >= 400 ? true : false
return show
}
},
methods: {
// 回到顶部
toTop() {
let obj = {
scrollTop: 0
}
uni.pageScrollTo(obj)
}
}
}
</script>
<style lang="scss" scoped>
.totop {
position: fixed;
right: 40rpx;
z-index: 999;
.totop_content {
width: 70rpx;
height: 70rpx;
color: $uni-text-color-inverse;
background: $uni-bg-color-mask;
display: flex;
flex-direction: column;
border-radius: 50%;
font-size: 18rpx;
.img_wrapper {
text-align: center;
image {
width: 30rpx;
height: 15rpx;
margin-top: 12rpx;
}
}
text {
text-align: center;
}
}
}
</style>