fs-back-top.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="fs-back-top" :style="{ right, bottom }" @click="handleClick" v-if="visible">
  3. <fs-icon type="icon-arrow-up" size="50rpx" color="#fff"></fs-icon>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * 回到顶部组件
  9. * @description 回到顶部组件
  10. * @property {String, Number} scrollTop useScrollTop
  11. * @property {String} top 距离顶部多大时显示返回顶部
  12. * @property {String} right “返回顶部”距离页面右边距
  13. * @property {String} bottom “返回顶部”距离页面下边距
  14. */
  15. export default {
  16. name: 'fs-back-top'
  17. }
  18. </script>
  19. <script setup>
  20. import { computed, watch } from 'vue'
  21. const props = defineProps({
  22. scrollTop: {
  23. type: [String, Number],
  24. required: true
  25. },
  26. top: {
  27. type: String,
  28. default: '150px'
  29. },
  30. right: {
  31. type: String,
  32. default: '40rpx'
  33. },
  34. bottom: {
  35. type: String,
  36. default: '40rpx'
  37. }
  38. })
  39. const visible = computed(() => {
  40. return parseFloat(props.scrollTop) >= parseFloat(props.top)
  41. })
  42. const handleClick = () => {
  43. uni.pageScrollTo({
  44. scrollTop: 0,
  45. duration: 100
  46. })
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .fs-back-top {
  51. position: fixed;
  52. width: 90rpx;
  53. height: 90rpx;
  54. border-radius: 50%;
  55. background-color: #606266;
  56. opacity: 0.5;
  57. z-index: 100;
  58. display: flex;
  59. justify-content: center;
  60. align-items: center;
  61. margin-bottom: var(--window-bottom);
  62. }
  63. </style>