-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
93 lines (85 loc) · 1.65 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div>
<div id="top"></div>
<transition name="fade">
<div v-if="show" class="preloader">
<div class="preloader__inner">
<div class="preloader__icon">
<span></span>
<span></span>
</div>
</div>
</div>
</transition>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
<transition name="scrolltop">
<a v-if="scrollPosition > 300" href="javascript:void(0);" @click="scrollingTop" class="scrollToTop"><i
class="fa-solid fa-arrow-up-from-bracket"></i></a>
</transition>
</div>
</template>
<script>
export default {
name: 'DefaultApp',
data() {
return {
show: true,
scrollPosition: 0
}
},
watch: {
'$route'() {
this.show = true;
setTimeout(() => {
this.show = false;
}, 300)
}
},
created() {
this.show = false;
if (process.client) {
window.addEventListener("scroll", this.handleScroll);
}
},
destroyed() {
if (process.client) {
window.removeEventListener("scroll", this.handleScroll);
}
},
methods: {
handleScroll() {
if (process.client) {
this.scrollPosition = window.scrollY
}
},
scrollingTop() {
window.scrollTo(0, 0)
}
},
}
</script>
<style lang="scss" scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 1s;
}
.fade-enter,
.fade-leave-to {
opacity: 0
}
.scrolltop-enter-active,
.scrolltop-leave-active {
transition: all 0.25s ease-out;
}
.scrolltop-enter-from {
opacity: 0;
// transform: translateY(10vh);
bottom: 0vh;
}
.scrolltop-leave-to {
opacity: 0;
bottom: 0vh;
}
</style>