BackToTheTop.vue 926 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <div class="pageTop" v-intersect="onTopIntersect"/>
  3. <client-only>
  4. <v-btn
  5. v-if="isVisible"
  6. aria-label="Back to the top of the page"
  7. :size="48"
  8. @click="onClick"
  9. class="back-to-the-top"
  10. >
  11. <v-icon>fas fa-arrow-up</v-icon>
  12. </v-btn>
  13. </client-only>
  14. </template>
  15. <script setup lang="ts">
  16. const isVisible: Ref<boolean> = ref(false)
  17. const onTopIntersect = (intersect: boolean) => {
  18. isVisible.value = !intersect
  19. }
  20. const onClick = () => {
  21. window.scrollTo({ top: 0, behavior: 'smooth' });
  22. }
  23. </script>
  24. <style scoped lang="scss">
  25. .pageTop {
  26. position: absolute;
  27. top: 0;
  28. height: 300px;
  29. width: 0;
  30. }
  31. .back-to-the-top {
  32. position: fixed;
  33. right: 5%;
  34. bottom: 58px;
  35. z-index: 100;
  36. border-radius: 24px;
  37. background: rgb(var(--v-theme-primary));
  38. color: rgb(var(--v-theme-on-primary));
  39. @media (max-width: 600px) {
  40. bottom: 30px;
  41. }
  42. }
  43. </style>