siteBar.vue 2.3 KB

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