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