siteBar.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div class="site-bar" v-show="1">
  3. <div class="btn wechat">
  4. <svg-icon icon-class="wechat" />
  5. <img class="show-img z-50" :src="imagePathBabel(platform.wx_qrc)" alt="">
  6. </div>
  7. <div class="btn top" @click="toTop" >
  8. <svg-icon icon-class="top" />
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. // 网页侧边栏小工具
  14. import {imagePathBabel} from "@/tools/imagePath";
  15. export default {
  16. name: "siteBar",
  17. props:{
  18. lang: {
  19. type: String,
  20. default: 'cn'
  21. },
  22. },
  23. data() {
  24. return {
  25. platform: this.$store.getters.platform
  26. }
  27. },
  28. // 指令
  29. directives:{
  30. // 滚动超过一屏时显示元素,否则隐藏
  31. show:{
  32. inserted(el){
  33. const elHeight = el.offsetHeight;
  34. const winHeight = window.innerHeight;
  35. const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  36. if (elHeight + scrollTop > winHeight){
  37. el.style.display = 'block';
  38. }else{
  39. el.style.display = 'none';
  40. }
  41. window.addEventListener('scroll',()=>{
  42. const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  43. if (elHeight + scrollTop > winHeight){
  44. el.style.display = 'block';
  45. }else{
  46. el.style.display = 'none';
  47. }
  48. })
  49. }
  50. }
  51. },
  52. methods: {
  53. toTop() {
  54. // 缓慢移动到顶部
  55. window.scrollTo({
  56. top: 0,
  57. behavior: "smooth"
  58. });
  59. },
  60. imagePathBabel
  61. }
  62. }
  63. </script>
  64. <style scoped>
  65. .site-bar{
  66. width: 50px;
  67. height: auto;
  68. position: fixed;
  69. right: 30px;
  70. bottom: 30px;
  71. /*transform: translateY(-50%);*/
  72. }
  73. @media screen and (min-width: 1024px) {
  74. .site-bar{
  75. right: 180px;
  76. bottom: 26%;
  77. }
  78. }
  79. .site-bar .btn{
  80. width: 50px;
  81. height: 50px;
  82. display: flex;
  83. justify-content: center;
  84. align-items: center;
  85. font-size: 2rem;
  86. cursor: pointer;
  87. background-color: #f5f5f5;
  88. border-radius: 50%;
  89. box-shadow: 0 0 5px #dedede;
  90. color: #999999;
  91. margin-bottom: 10px;
  92. }
  93. .site-bar .btn:hover{
  94. background-color: #dedede;
  95. color: #af4141;
  96. }
  97. .wechat{
  98. position: relative;
  99. }
  100. .wechat .show-img{
  101. position: absolute;
  102. bottom: 50px;
  103. right: 50px;
  104. display: block;
  105. width: 0;
  106. height: 0;
  107. max-width: none;
  108. border-radius: 5px;
  109. box-shadow: 1px 1px 7px 5px #dedede;
  110. opacity: 0;
  111. transition: all 0.5s;
  112. }
  113. .wechat:hover .show-img{
  114. opacity: 1;
  115. width: 180px;
  116. height: 180px;
  117. }
  118. </style>