headerSection.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="headerSection">
  3. <div class="header-container width1200">
  4. <router-link :to="{ path: '/' }"
  5. class="logo">
  6. <img src="../assets/images/logoWhile.png"
  7. width="100%"
  8. alt="">
  9. </router-link>
  10. <div class="menu">
  11. <a :class="checkActive==1?'active':''"
  12. @click="change(1,'banner')">平台介绍</a>
  13. <a :class="checkActive==2?'active':''"
  14. @click="change(2,'infos')">产品优势</a>
  15. <a :class="checkActive==3?'active':''"
  16. @click="change(3,'detail')">考生指引</a>
  17. <a :class="checkActive==4?'active':''"
  18. @click="change(4,'videoList')">操作指南</a>
  19. <a :class="checkActive==5?'active':''"
  20. @click="change(5,'consult')">行业咨询</a>
  21. <a :class="checkActive==6?'active':''"
  22. @click="change(6,'aboutUs')">关于我们</a>
  23. <div class="bandBtn"
  24. @click="goKu">合作机构</div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import Bus from '../views/index/blocks/eventBus'
  31. import { scrollAnimation } from '@/util/scroll'
  32. export default {
  33. name: 'headerSection',
  34. props: ['name'],
  35. data () {
  36. return {
  37. checkActive: 1,
  38. topList: []
  39. }
  40. },
  41. created () {
  42. },
  43. mounted () {
  44. scrollTo(0, 0);
  45. let url = this.$route
  46. if (url.path.indexOf('detile') != -1) {
  47. this.checkActive = 5
  48. }
  49. this.$nextTick(res => {
  50. this.topList = this.getTop(['banner', 'infos', 'detail', 'videoList', 'consult', 'aboutUs'])
  51. })
  52. window.addEventListener('scroll', this.onContentScroll, true)
  53. Bus.$on('gotoDetail', (res => {
  54. // 控制页面滚动
  55. this.change(3, 'detail')
  56. }))
  57. },
  58. methods: {
  59. getTop (nameList) {
  60. let arr = []
  61. nameList.forEach(item => {
  62. let top = document.getElementById(item).offsetTop - 78
  63. arr.push(top)
  64. })
  65. arr.sort(function (a, b) { return a - b });
  66. return arr
  67. },
  68. change (num, name) {
  69. let url = this.$route.path
  70. let top = document.getElementById(name).offsetTop - 76
  71. const currentY = document.documentElement.scrollTop || document.body.scrollTop
  72. if (url != '/') {
  73. this.$router.push('/')
  74. this.checkActive = num;
  75. scrollAnimation(currentY, top)
  76. // scrollTo(0, top);
  77. } else {
  78. this.checkActive = num;
  79. scrollAnimation(currentY, top)
  80. // scrollTo(0, top);
  81. }
  82. },
  83. goKu () {
  84. window.open('https://kj.colexiu.com/#/login?returnUrl=%2F', '_blank');
  85. },
  86. onContentScroll (e) {
  87. // this.topList = this.getTop(['banner', 'infos', 'detail', 'videoList', 'consult', 'aboutUs'])
  88. let target = e.target || e.srcElement
  89. this.scrollTop = target.scrollingElement.scrollTop
  90. if (this.scrollTop < this.topList[1]) {
  91. this.checkActive = 1
  92. } else if (this.scrollTop >= this.topList[1] && this.scrollTop < this.topList[2]) {
  93. this.checkActive = 2
  94. } else if (this.scrollTop >= this.topList[2] && this.scrollTop < this.topList[3]) {
  95. this.checkActive = 3
  96. } else if (this.scrollTop >= this.topList[3] && this.scrollTop < this.topList[4]) {
  97. this.checkActive = 4
  98. } else if (this.scrollTop >= this.topList[4] && this.scrollTop < this.topList[5]) {
  99. this.checkActive = 5
  100. } else if (this.scrollTop >= this.topList[5]) {
  101. this.checkActive = 6
  102. }
  103. },
  104. }
  105. }
  106. </script>
  107. <style lang="less" scoped>
  108. .bandBtn {
  109. width: 112px;
  110. height: 30px;
  111. background: #2dc7aa;
  112. border-radius: 4px;
  113. color: #fff;
  114. margin-left: 70px;
  115. line-height: 30px;
  116. cursor: pointer;
  117. position: relative;
  118. &:hover {
  119. background-color: #2ac0a3;
  120. }
  121. }
  122. .wall {
  123. height: 82px;
  124. }
  125. .headerSection {
  126. background-color: rgba(0, 0, 0, 0.7);
  127. position: fixed;
  128. width: 100%;
  129. top: 0px;
  130. z-index: 1000;
  131. .header-container {
  132. margin: 0 auto;
  133. // overflow: hidden;
  134. display: flex;
  135. align-items: center;
  136. flex-direction: row;
  137. justify-content: space-between;
  138. height: 76px;
  139. }
  140. .logo {
  141. // float: left;
  142. width: 159px;
  143. height: 48px;
  144. }
  145. .menu {
  146. display: flex;
  147. flex-direction: row;
  148. font-size: 16px;
  149. align-items: center;
  150. a {
  151. cursor: pointer;
  152. margin-left: 44px;
  153. color: #fff;
  154. text-decoration: none;
  155. position: relative;
  156. // display: block;
  157. text-decoration: none;
  158. text-transform: uppercase;
  159. transition: 0.5s;
  160. &::after {
  161. position: absolute;
  162. content: "";
  163. top: 140%;
  164. left: 0;
  165. width: 100%;
  166. height: 3px;
  167. background-color: #2dc7aa;
  168. z-index: 100;
  169. transform: scaleX(0);
  170. transform-origin: right;
  171. transition: transform 0.5s;
  172. }
  173. &:hover,
  174. &.hover {
  175. color: #2dc7aa;
  176. font-weight: 600;
  177. }
  178. &:hover::after {
  179. transform: scaleX(1);
  180. transform-origin: left;
  181. }
  182. }
  183. }
  184. a.active {
  185. color: #2dc7aa !important;
  186. font-weight: 600;
  187. &::after {
  188. position: absolute;
  189. content: "";
  190. top: 140%;
  191. left: 0;
  192. width: 100%;
  193. height: 3px;
  194. background-color: #2dc7aa;
  195. z-index: 100;
  196. transform: scaleX(1);
  197. transform-origin: left;
  198. }
  199. }
  200. }
  201. </style>