File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ // Track scroll position
3+ const showButton = ref (false )
4+
5+ // Show button after scrolling down 300px
6+ function handleScroll() {
7+ showButton .value = window .scrollY > 300
8+ }
9+
10+ // Scroll to top smoothly
11+ function scrollToTop() {
12+ window .scrollTo ({ top: 0 , behavior: ' smooth' })
13+ }
14+
15+ // Add/remove scroll listener
16+ onMounted (() => {
17+ window .addEventListener (' scroll' , handleScroll , { passive: true })
18+ })
19+
20+ onUnmounted (() => {
21+ window .removeEventListener (' scroll' , handleScroll )
22+ })
23+ </script >
24+
25+ <template >
26+ <Transition
27+ enter-active-class =" transition-all duration-200"
28+ enter-from-class =" opacity-0 translate-y-2"
29+ enter-to-class =" opacity-100 translate-y-0"
30+ leave-active-class =" transition-all duration-200"
31+ leave-from-class =" opacity-100 translate-y-0"
32+ leave-to-class =" opacity-0 translate-y-2"
33+ >
34+ <button
35+ v-if =" showButton"
36+ class =" md:hidden fixed bottom-4 right-4 z-40 w-12 h-12 bg-bg-elevated border border-border rounded-full shadow-lg flex items-center justify-center text-fg-muted hover:text-fg transition-colors active:scale-98"
37+ aria-label =" Scroll to top"
38+ @click =" scrollToTop"
39+ >
40+ <span class =" i-carbon-arrow-up w-5 h-5" />
41+ </button >
42+ </Transition >
43+ </template >
Original file line number Diff line number Diff line change @@ -759,5 +759,8 @@ defineOgImageComponent('Package', {
759759 </p >
760760 <NuxtLink to =" /" class =" btn" > Go back home </NuxtLink >
761761 </div >
762+
763+ <!-- Scroll to top button (mobile only) -->
764+ <ScrollToTop />
762765 </main >
763766</template >
You can’t perform that action at this time.
0 commit comments