1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-06-11 12:49:30 +08:00
Files
uni-halo/components/scroll-btn/scroll-btn.vue
T
2022-12-12 00:30:47 +08:00

80 lines
1.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="scroll-btn" :style="{ bottom: bottom }" @click.stop="fnScroll()">
<text v-if="_scrollTop >= 180" class="iconfont icon-long-arrow-up"></text>
<text v-else class="iconfont icon-long-arrow-down"></text>
</view>
</template>
<script>
import throttle from '@/utils/throttle.js';
export default {
name: 'scroll-btn',
props: {
bottom: {
type: String,
default: '180rpx'
},
scrollTop: {
type: Number,
default: 0
}
},
data() {
return { _scrollTop: 0 };
},
watch: {
scrollTop(val) {
this._scrollTop = val;
console.log('监听1', val);
this.$forceUpdate();
}
},
created() {
this._scrollTop = this.scrollTop;
},
methods: {
fnScroll() {
throttle(() => {
const isTop = this._scrollTop >= 180;
this._scrollTop = isTop ? 0 : 999999;
uni.pageScrollTo({
duration: 500,
scrollTop: this._scrollTop
});
this.$emit('update:scrollTop', this._scrollTop);
});
}
}
};
</script>
<style scoped lang="scss">
.scroll-btn {
position: fixed;
// bottom: 200rpx;
// right: -90rpx;
right: 52rpx;
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
border-radius: 50%;
border: 4rpx solid #ffffff;
background-color: #bfe9ef;
box-shadow: 0rpx 4rpx 24rpx rgba(0, 0, 0, 0.1);
z-index: 99;
transition: right 0.5s ease-in-out;
&.is-show {
right: 52rpx;
}
.iconfont {
font-size: 36rpx;
color: #555;
}
}
</style>