Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 76x 76x 76x 76x 3x 76x 76x 76x | <template>
<Transition name="fade">
<div v-if="isVisible" class="floating-actions" aria-label="floating page actions">
<button
class="btn btn-outline-secondary shadow action-btn"
:title="props.scrollTopTitle"
:aria-label="props.scrollTopTitle"
@click="scrollToTop"
>
<span>{{ props.scrollTopTitle }}</span>
<font-awesome-icon icon="fa-solid fa-arrow-up" />
</button>
</div>
</Transition>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
const props = withDefaults(
defineProps<{
scrollTopTitle?: string
}>(),
{
scrollTopTitle: 'Back to top'
}
)
const isVisible = ref(false)
const SCROLL_THRESHOLD = 200
function getScrollableElement(): HTMLElement | null {
return (
(document.querySelector('.virtual-scroll-wrapper') as HTMLElement | null) ??
(document.querySelector('.main-content') as HTMLElement | null)
)
}
// Use capture phase: scroll events don't bubble, but capture intercepts them
// from any scrollable descendant — including VirtualCardGrid rendered after mount.
function onScroll() {
const el = getScrollableElement()
isVisible.value = !!el && el.scrollTop > SCROLL_THRESHOLD
}
function scrollToTop() {
const el = getScrollableElement()
if (el) {
// Use instant scroll: smooth + TanStack virtualizer conflict at each animation frame
el.scrollTop = 0
} else {
window.scrollTo({ top: 0, behavior: 'instant' })
}
}
onMounted(() => {
document.addEventListener('scroll', onScroll, { passive: true, capture: true })
})
onUnmounted(() => {
document.removeEventListener('scroll', onScroll, { capture: true } as EventListenerOptions)
})
</script>
<style scoped>
.floating-actions {
position: fixed;
right: 1rem;
bottom: 1rem;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.action-btn {
height: 2.5rem;
padding: 0 0.9rem;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.4rem;
border-radius: 0.4rem;
background: #fff;
border: 1px solid var(--bs-secondary, #6c757d);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.action-btn:hover,
.action-btn:focus-visible,
.action-btn:active {
background: #6c757d !important;
border: 1.5px solid #6c757d !important;
color: #fff !important;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.2s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
@media (max-width: 767px) {
.floating-actions {
right: 0.75rem;
bottom: 0.75rem;
}
.action-btn {
height: 2.3rem;
padding: 0 0.75rem;
}
}
</style>
|