index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <script setup lang="ts">
  2. defineOptions({
  3. name: 'FixedActionBar',
  4. })
  5. const isBottom = ref(false)
  6. onMounted(() => {
  7. onScroll()
  8. window.addEventListener('scroll', onScroll)
  9. })
  10. onUnmounted(() => {
  11. window.removeEventListener('scroll', onScroll)
  12. })
  13. function onScroll() {
  14. // 变量scrollTop是滚动条滚动时,滚动条上端距离顶部的距离
  15. const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
  16. // 变量windowHeight是可视区的高度
  17. const windowHeight = document.documentElement.clientHeight || document.body.clientHeight
  18. // 变量scrollHeight是滚动条的总高度(当前可滚动的页面的总高度)
  19. const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight
  20. // 滚动条到底部
  21. isBottom.value = Math.ceil(scrollTop + windowHeight) >= scrollHeight
  22. }
  23. </script>
  24. <template>
  25. <div
  26. class="fixed-action-bar bottom-0 z-4 bg-[var(--g-container-bg)] p-5 text-center transition" :class="{ shadow: !isBottom }" data-fixed-calc-width
  27. >
  28. <slot />
  29. </div>
  30. </template>
  31. <style scoped>
  32. .fixed-action-bar {
  33. box-shadow: 0 0 1px 0 var(--g-box-shadow-color);
  34. &.shadow {
  35. box-shadow: 0 -10px 10px -10px var(--g-box-shadow-color);
  36. }
  37. }
  38. </style>