sidebar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div class="client-sidebar mta-hidden-xs">
  3. <ul>
  4. <!-- <li><a class="sidebar-default-box" :href="linkForKefu" target="_blank"><i></i>-->
  5. <!-- <p>在线资讯</p></a></li>-->
  6. <li>
  7. <div class="sidebar-default-box"><i></i>
  8. <p>电话资讯</p></div>
  9. <div class="sidebar-hover-box">
  10. <span>服务热线</span><h4>400-099-0883</h4>
  11. </div>
  12. </li>
  13. <li>
  14. <div class="sidebar-default-box"><i></i>
  15. <p>客户经理</p></div>
  16. <div class="sidebar-hover-box">
  17. <img :src="img1">
  18. </div>
  19. </li>
  20. <li v-if="btnFlag"><i @click="backTop"></i>
  21. <p>置顶</p></li>
  22. </ul>
  23. </div>
  24. </template>
  25. <script>
  26. import {linkForKefu} from "~/defaultConfig"
  27. export default {
  28. name: 'mtaSidebar',
  29. // vue的两个生命钩子,这里不多解释。
  30. // window对象,所有浏览器都支持window对象。它表示浏览器窗口,监听滚动事件
  31. mounted() {
  32. window.addEventListener('scroll', this.scrollToTop)
  33. },
  34. destroyed() {
  35. window.removeEventListener('scroll', this.scrollToTop)
  36. },
  37. data() {
  38. return {
  39. btnFlag: false,
  40. img1: require('static/codeImage/code-jingli.png'),
  41. linkForKefu
  42. }
  43. },
  44. methods: {
  45. // 点击图片回到顶部方法,加计时器是为了过渡顺滑
  46. backTop() {
  47. const that = this
  48. let timer = setInterval(() => {
  49. let ispeed = Math.floor(-that.scrollTop / 5)
  50. document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
  51. if (that.scrollTop === 0) {
  52. clearInterval(timer)
  53. }
  54. }, 16)
  55. },
  56. // 为了计算距离顶部的高度,当高度大于60显示回顶部图标,小于60则隐藏
  57. scrollToTop() {
  58. const that = this
  59. let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  60. that.scrollTop = scrollTop
  61. if (that.scrollTop > 60) {
  62. that.btnFlag = true
  63. } else {
  64. that.btnFlag = false
  65. }
  66. }
  67. }
  68. };
  69. </script>
  70. <style lang="scss" scoped>
  71. .client-sidebar {
  72. //display: none;
  73. position: fixed;
  74. z-index: 100;
  75. top: 200px;
  76. right: 0;
  77. li {
  78. width: 94px;
  79. height: 102px;
  80. position: relative;
  81. i {
  82. width: 45px;
  83. height: 40px;
  84. display: block;
  85. margin: 16px auto;
  86. background-position: center;
  87. background-size: contain;
  88. background-repeat: no-repeat
  89. }
  90. p {
  91. font-size: 18px;
  92. color: #00b96b;
  93. text-align: center;
  94. }
  95. .sidebar-default-box {
  96. border: 1px solid #eee;
  97. box-sizing: border-box;
  98. background: #fff;
  99. z-index: 2;
  100. background: #fff;
  101. position: absolute;
  102. top: 0;
  103. left: 0;
  104. right: 0;
  105. bottom: 0;
  106. }
  107. .sidebar-hover-box {
  108. width: 220px;
  109. height: 102px;
  110. display: block;
  111. padding: 24px;
  112. border: 1px solid #eee;
  113. transition: all 0.5s;
  114. position: absolute;
  115. right: -150px;
  116. background: #fff;
  117. top: 0;
  118. box-sizing: border-box;
  119. z-index: 1;
  120. span {
  121. font-size: 16px;
  122. display: block;
  123. color: #1f1f1f;
  124. margin-bottom: 10px
  125. }
  126. h4 {
  127. font-size: 18px;
  128. color: #00b96b;
  129. font-weight: bold;
  130. }
  131. img {
  132. height: 50px;
  133. width: auto;
  134. }
  135. }
  136. }
  137. li:hover {
  138. .sidebar-default-box {
  139. }
  140. .sidebar-hover-box {
  141. right: 92px;
  142. }
  143. }
  144. //li:nth-child(1) i {
  145. // background-image: url("~static/gangweiIcon/z142.png");
  146. //}
  147. li:nth-child(1) i {
  148. background-image: url("~static/gangweiIcon/z143.png");
  149. }
  150. li:nth-child(2) i {
  151. background-image: url("~static/gangweiIcon/z145.png");
  152. }
  153. li:nth-child(3) i {
  154. background-image: url("~static/gangweiIcon/z144.png");
  155. }
  156. }
  157. </style>