保誠-保戶業務員媒合平台
Mila
2021-11-12 3735262f83ba523cae560cd52478b908996d162d
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
<template>
    <el-button
        @click="topFunction"
        id="topBtn"
        :style="{display: buttonDisplay}"
    >
        <i class="icon-top"></i>
        <div>Top</div>
    </el-button>
</template>
 
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
 
@Component
export default class UiGoToTop extends Vue {
    buttonDisplay = 'none';
 
    created() {
        if (process.browser) {
            document.body.addEventListener('scroll', this.scrollFunction);
        }
    }
 
    scrollFunction() {
        if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
            this.buttonDisplay = "block";
        } else {
            this.buttonDisplay = "none";
        }
    }
 
    topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
 
    destroyed() {
        document.body.removeEventListener('scroll', this.scrollFunction);
    }
}
</script>
 
<style lang="scss">
#topBtn {
  display: none;
  position: fixed;
  bottom: 30px;
  right: 20px;
  z-index: 99;
  background-color: #666666;
  color: $PRIMARY_WHITE;
  cursor: pointer;
  width: 68px;
  height: 68px;
  border-radius: 50px;
  border: none;
  transition: width height;
  transition-duration: 0.5s;
  font-size: 16px;
 
  &:hover,&:focus {
      transform: scale(0.9);
      transition: transform;
      transition-duration: 0.5s;
      background-color: $MID_GREY;
  }
}
</style>