This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/ScrollButton.vue

54 lines
1.4 KiB
Vue
Raw Normal View History

2020-09-04 08:51:26 -07:00
<template>
2022-05-26 02:45:38 -07:00
<div class="scroll-btn d-print-none" @click.prevent="scroll" :style="`opacity: ${shown ? 1 : 0}`">
2020-10-31 08:08:48 -07:00
<SquareButton link="#" :colour="colour" :aria-label="$t('table.scrollUp')">
2020-09-04 08:51:26 -07:00
<Icon v="arrow-alt-up"/>
</SquareButton>
</div>
</template>
<script>
export default {
props: {
colour: { 'default': null },
},
data() {
return {
shown: false,
}
},
2021-01-21 11:15:55 -08:00
created() {
2020-09-04 08:51:26 -07:00
if (process.client) {
this.updateShown();
2021-01-21 11:15:55 -08:00
window.addEventListener('scroll', this.updateShown);
}
},
destroyed() {
if (process.client) {
document.removeEventListener('scroll', this.updateShown);
2020-09-04 08:51:26 -07:00
}
},
methods: {
scroll() {
document.body.scrollTop = 0;
document.querySelector('html').scrollTop = 0;
},
updateShown() {
const st = document.body.scrollTop || document.querySelector('html').scrollTop;
this.shown = st > 300;
}
},
}
</script>
<style lang="scss" scoped>
@import "assets/variables";
2020-09-04 08:51:26 -07:00
.scroll-btn {
position: fixed;
bottom: $spacer;
right: $spacer;
transition: all .5s ease-in-out;
2021-01-21 09:56:08 -08:00
z-index: 1030;
2020-09-04 08:51:26 -07:00
}
</style>