fs-back-top.vue 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view
  3. class="fs-back-top"
  4. :style="{right, bottom}"
  5. @click="handleClick"
  6. v-if="visible">
  7. <fs-icon type="icon-arrow-up" size="50rpx" color="#fff"></fs-icon>
  8. </view>
  9. </template>
  10. <script setup>
  11. import { computed, watch } from 'vue'
  12. const props = defineProps({
  13. scrollTop: {
  14. type: [String, Number],
  15. required: true
  16. },
  17. top: {
  18. type: String,
  19. default: '150px'
  20. },
  21. right: {
  22. type: String,
  23. default: '40rpx'
  24. },
  25. bottom: {
  26. type: String,
  27. default: '40rpx'
  28. }
  29. })
  30. const visible = computed(() => {
  31. return parseFloat(props.scrollTop) >= parseFloat(props.top)
  32. })
  33. const handleClick = () => {
  34. uni.pageScrollTo({
  35. scrollTop: 0,
  36. duration: 100
  37. })
  38. }
  39. </script>
  40. <style lang="scss" scoped>
  41. .fs-back-top{
  42. position: fixed;
  43. width: 90rpx;
  44. height: 90rpx;
  45. border-radius: 50%;
  46. background-color: #606266;
  47. opacity: .5;
  48. z-index: 100;
  49. display: flex;
  50. justify-content: center;
  51. align-items: center;
  52. margin-bottom: var(--window-bottom);
  53. }
  54. </style>