| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 1 | <template> |
| 2 | <b-button |
| 3 | id="scrollToTopBtn" |
| 4 | class="btn-top btn-icon-only" |
| Derick Montague | 86e11ad | 2021-01-04 11:19:08 -0600 | [diff] [blame] | 5 | :class="{ 'show-btn': showButton }" |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 6 | variant="secondary" |
| 7 | :title="$t('global.ariaLabel.scrollToTop')" |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 8 | @click="scrollToTop" |
| 9 | > |
| 10 | <icon-up-to-top /> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 11 | <span class="visually-hidden-focusable"> |
| 12 | {{ $t('global.ariaLabel.scrollToTop') }} |
| 13 | </span> |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 14 | </b-button> |
| 15 | </template> |
| 16 | |
| 17 | <script> |
| 18 | import UpToTop24 from '@carbon/icons-vue/es/up-to-top/24'; |
| 19 | |
| 20 | import { debounce } from 'lodash'; |
| Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 21 | import { useI18n } from 'vue-i18n'; |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 22 | |
| 23 | export default { |
| 24 | name: 'BackToTop', |
| 25 | components: { IconUpToTop: UpToTop24 }, |
| 26 | data() { |
| 27 | return { |
| Ed Tanous | 883a0d5 | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 28 | $t: useI18n().t, |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 29 | showButton: false, |
| 30 | }; |
| 31 | }, |
| 32 | created() { |
| 33 | window.addEventListener('scroll', debounce(this.handleScroll, 200)); |
| 34 | }, |
| 35 | methods: { |
| 36 | handleScroll() { |
| 37 | document.documentElement.scrollTop > 500 |
| 38 | ? (this.showButton = true) |
| 39 | : (this.showButton = false); |
| 40 | }, |
| 41 | scrollToTop() { |
| 42 | document.documentElement.scrollTo({ |
| 43 | top: 0, |
| 44 | behavior: 'smooth', |
| 45 | }); |
| 46 | }, |
| 47 | }, |
| 48 | }; |
| 49 | </script> |
| 50 | |
| 51 | <style lang="scss" scoped> |
| 52 | .btn-top { |
| 53 | position: fixed; |
| 54 | bottom: 24px; |
| 55 | right: 24px; |
| Derick Montague | 86e11ad | 2021-01-04 11:19:08 -0600 | [diff] [blame] | 56 | |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 57 | box-shadow: $box-shadow; |
| Derick Montague | 86e11ad | 2021-01-04 11:19:08 -0600 | [diff] [blame] | 58 | visibility: hidden; |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 59 | opacity: 0; |
| 60 | transition: $transition-base; |
| Derick Montague | 86e11ad | 2021-01-04 11:19:08 -0600 | [diff] [blame] | 61 | z-index: $zindex-fixed; |
| 62 | |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 63 | @media (min-width: 1600px) { |
| 64 | left: 1485px; |
| 65 | right: auto; |
| 66 | } |
| 67 | } |
| Derick Montague | 86e11ad | 2021-01-04 11:19:08 -0600 | [diff] [blame] | 68 | .show-btn { |
| 69 | visibility: visible; |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 70 | opacity: 1; |
| Dixsie Wolmers | 970ea7d | 2020-11-16 16:46:01 -0600 | [diff] [blame] | 71 | } |
| 72 | </style> |