1
1
<template >
2
2
<transition name =" fade" >
3
- <div
4
- v-if =" show"
5
- class =" go-to-top"
6
- @click =" scrollToTop"
7
- >
3
+ <div v-if =" show" class =" go-to-top" @click =" scrollToTop" >
8
4
<svg
5
+ width =" 16px"
6
+ height =" 16px"
7
+ viewBox =" 0 0 16 16"
8
+ version =" 1.1"
9
9
xmlns =" http://www.w3.org/2000/svg"
10
- viewBox = " 0 0 49.484 28.284 "
10
+ xmlns:xlink = " http://www.w3.org/1999/xlink "
11
11
>
12
- <g transform =" translate(-229 -126.358)" >
13
- <rect
14
- fill =" currentColor"
15
- width =" 35"
16
- height =" 5"
17
- rx =" 2"
18
- transform =" translate(229 151.107) rotate(-45)"
19
- />
20
- <rect
21
- fill =" currentColor"
22
- width =" 35"
23
- height =" 5"
24
- rx =" 2"
25
- transform =" translate(274.949 154.642) rotate(-135)"
26
- />
12
+ <g stroke =" none" stroke-width =" 1" fill =" none" fill-rule =" evenodd" >
13
+ <path
14
+ d =" M8.71335931,15.2865297 C8.61179683,16.2090609 7.32293758,16.1267953 7.27304695,15.2865297 C7.27175008,14.6475142 7.27175008,5.26479636 7.27175008,5.26479636 L2.83675052,9.54548344 C2.14185995,10.1440615 1.3143288,9.18731159 1.83135998,8.55773353 C3.79557855,6.65310872 7.3202657,3.24515592 7.40179694,3.16632781 C7.72696878,2.81306222 8.23887498,2.79476534 8.58495308,3.16632781 C9.23193739,3.7919215 14.0334057,8.42146792 14.1791557,8.58804603 C14.66614,9.19338972 13.8787807,10.0892021 13.2066089,9.58451469 C13.0329683,9.43717095 8.71468744,5.26462448 8.71468744,5.26462448 L8.71335931,15.2865297 Z M1.81868811,-8.54871729e-14 L14.1075619,-8.54871729e-14 L14.1075619,1.39509361 L1.81868811,1.39509361 L1.81868811,-8.54871729e-14 Z"
15
+ fill =" #FFFFFF"
16
+ fill-rule =" nonzero"
17
+ ></path >
27
18
</g >
28
19
</svg >
29
20
</div >
30
21
</transition >
31
22
</template >
32
23
33
24
<script lang="ts">
34
- import { debounce } from ' lodash'
35
- import { defineComponent , onMounted , computed , ref } from ' vue'
25
+ import { debounce } from ' lodash' ;
26
+ import { defineComponent , onMounted , computed , ref } from ' vue' ;
36
27
export default defineComponent ({
37
28
name: ' BackToTop' ,
38
29
props: {
@@ -42,58 +33,62 @@ export default defineComponent({
42
33
},
43
34
},
44
35
setup(props ) {
45
- const scrollTop = ref <number | null >(null )
36
+ const scrollTop = ref <number | null >(null );
46
37
const show = computed (() => {
47
- return scrollTop .value ! > props .threshold
48
- })
38
+ return scrollTop .value ! > props .threshold ;
39
+ });
49
40
const scrollToTop = () => {
50
- window .scrollTo ({ top: 0 , behavior: ' smooth' })
51
- scrollTop .value = 0
52
- }
41
+ window .scrollTo ({ top: 0 , behavior: ' smooth' });
42
+ scrollTop .value = 0 ;
43
+ };
53
44
const getScrollTop = () => {
54
- return (
55
- window .pageYOffset ||
56
- document .documentElement .scrollTop ||
57
- document .body .scrollTop ||
58
- 0
59
- )
60
- }
45
+ return window .pageYOffset || document .documentElement .scrollTop || document .body .scrollTop || 0 ;
46
+ };
61
47
onMounted (() => {
62
- scrollTop .value = getScrollTop ()
48
+ scrollTop .value = getScrollTop ();
63
49
window .addEventListener (
64
50
' scroll' ,
65
51
debounce (() => {
66
- scrollTop .value = getScrollTop ()
52
+ scrollTop .value = getScrollTop ();
67
53
}, 100 )
68
- )
69
- })
54
+ );
55
+ });
70
56
71
57
return {
72
58
show ,
73
59
scrollToTop ,
74
- }
60
+ };
75
61
},
76
- })
62
+ });
77
63
</script >
78
64
79
65
<style lang="scss" scoped>
80
66
.go-to-top {
81
67
cursor : pointer ;
82
68
position : fixed ;
83
69
display : flex ;
70
+ justify-content : center ;
71
+ align-items : center ;
84
72
bottom : 2rem ;
85
- right : calc ((100vw - 1440px ) / 2 + 144px );
86
- width : 22px ;
87
- color : var (--devui-brand );
73
+ right : 40px ;
74
+ width : 40px ;
75
+ height : 40px ;
76
+ border-radius : 50% ;
77
+ background-color : var (--devui-base-bg );
78
+ box-shadow : 0 6px 16px 0 var (--devui-shadow );
88
79
z-index : 1 ;
89
80
90
81
& :hover {
91
82
color : var (--devui-brand-hover );
92
83
}
93
84
94
85
& svg {
95
- width : 22px ;
96
- height : 22px ;
86
+ width : 16px ;
87
+ height : 16px ;
88
+
89
+ path {
90
+ fill : var (--devui-text );
91
+ }
97
92
}
98
93
}
99
94
0 commit comments