sidebar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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: 80px;
  76. right: 0;
  77. li {
  78. width: 94px;
  79. height: 102px;
  80. position: relative;
  81. cursor: pointer;
  82. i {
  83. width: 45px;
  84. height: 40px;
  85. display: block;
  86. margin: 16px auto;
  87. background-position: center;
  88. background-size: contain;
  89. background-repeat: no-repeat
  90. }
  91. p {
  92. font-size: 18px;
  93. color: #00b96b;
  94. text-align: center;
  95. }
  96. .sidebar-default-box {
  97. border: 1px solid #eee;
  98. box-sizing: border-box;
  99. background: #fff;
  100. z-index: 2;
  101. background: #fff;
  102. position: absolute;
  103. top: 0;
  104. left: 0;
  105. right: 0;
  106. bottom: 0;
  107. }
  108. .sidebar-hover-box {
  109. width: 220px;
  110. height: 102px;
  111. display: block;
  112. padding: 24px;
  113. border: 1px solid #eee;
  114. transition: all 0.5s;
  115. position: absolute;
  116. right: -150px;
  117. background: #fff;
  118. top: 0;
  119. box-sizing: border-box;
  120. z-index: 1;
  121. span {
  122. font-size: 16px;
  123. display: block;
  124. color: #1f1f1f;
  125. margin-bottom: 10px
  126. }
  127. h4 {
  128. font-size: 18px;
  129. color: #00b96b;
  130. font-weight: bold;
  131. }
  132. img {
  133. height: 50px;
  134. width: auto;
  135. }
  136. }
  137. }
  138. li:hover {
  139. .sidebar-default-box {
  140. }
  141. .sidebar-hover-box {
  142. right: 92px;
  143. }
  144. }
  145. //li:nth-child(1) i {
  146. // background-image: url("~static/gangweiIcon/z142.png");
  147. //}
  148. li:nth-child(1) i {
  149. background-image: url("~static/gangweiIcon/z143.png");
  150. }
  151. li:nth-child(2) i {
  152. background-image: url("~static/gangweiIcon/z145.png");
  153. }
  154. li:nth-child(3) i {
  155. background-image: url("~static/gangweiIcon/z144.png");
  156. }
  157. }
  158. </style>