sidebar.vue 4.2 KB

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