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.
2020-09-04 08:51:26 -07:00
|
|
|
<template>
|
|
|
|
<div class="scroll-btn" @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,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (process.client) {
|
|
|
|
this.updateShown();
|
|
|
|
window.addEventListener('scroll', _ => { this.updateShown(); });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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/style";
|
|
|
|
|
|
|
|
.scroll-btn {
|
|
|
|
position: fixed;
|
|
|
|
bottom: $spacer;
|
|
|
|
right: $spacer;
|
|
|
|
transition: all .5s ease-in-out;
|
|
|
|
}
|
|
|
|
</style>
|