-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathOneBackToTop.vue
88 lines (80 loc) · 1.43 KB
/
OneBackToTop.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
<template>
<button
class="one-back-to-top"
:class="{
scrolled: !top
}"
aria-hidden="true"
@click="scrollToTop"
>
<veui-icon
class="icon"
name="chevron-up"
:label="t('toTop')"
/>
</button>
</template>
<script>
import { Icon } from 'veui'
import i18n from 'veui/mixins/i18n'
import 'veui-theme-dls-icons/chevron-up'
import { debounce } from 'lodash'
export default {
name: 'one-back-to-top',
components: {
'veui-icon': Icon
},
mixins: [i18n],
data () {
return {
top: true
}
},
mounted () {
this.check = debounce(() => {
this.top = window.scrollY === 0
}, 300)
window.addEventListener('scroll', this.check)
this.check()
},
beforeDestroy () {
this.check.cancel()
window.removeEventListener('scroll', this.check)
},
methods: {
scrollToTop () {
window.scrollTo(0, 0)
}
}
}
</script>
<style lang="stylus" scoped>
.one-back-to-top
position fixed
right 35px
bottom 35px
width 43px
height 43px
border 1px solid #dbdbdb
border-radius 50%
opacity 0
outline none
box-shadow 0 0 2px #dbdbdb
cursor pointer
transition background-color 0.3s, opacity 0.3s
&:hover
&.focus-visible
background-color #f7f7f7
&:active
background-color #ececec
.icon
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
.scrolled
opacity 1
@media (max-width 480px)
.one-back-to-top
bottom 94px
</style>