header.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="header-container" :class="{'offset':isOffset}">
  3. <div class="inner-container">
  4. <img class="brand" :src="isOffset?require('../assets/logo-rev.png'):require('../assets/mainLogo.png')"/>
  5. <ul class="header-tab">
  6. <li class="header-tab-item active">首页</li>
  7. <li class="header-tab-item">申请代理</li>
  8. </ul>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. export default {
  14. name: "headerComponent",
  15. data(){
  16. return{
  17. isOffset:false,
  18. }
  19. },
  20. mounted(){
  21. window.addEventListener('scroll',this.scrollListener)
  22. },
  23. methods:{
  24. scrollListener(e){
  25. this.isOffset=!!window.pageYOffset;
  26. // console.log(window.pageYOffset);
  27. }
  28. }
  29. }
  30. </script>
  31. <style scoped lang="less">
  32. @import "../assets/less/_variable.less";
  33. .header-container{
  34. transition: all 0.25s ease;
  35. position: fixed;
  36. width: 100%;
  37. height: 80px;
  38. background-color: rgba(0, 0, 0, 0.2);
  39. z-index: 9;
  40. }
  41. .inner-container{
  42. position: relative;
  43. width: 1200px;
  44. margin: 0 auto;
  45. display: flex;
  46. flex-direction: row;
  47. & .brand{
  48. position: absolute;
  49. width: 100px;
  50. height: 33px;
  51. top: 50%;
  52. transform: translateY(-50%);
  53. }
  54. & .header-tab{
  55. margin-left: 135px;
  56. display: flex;
  57. flex-direction: row;
  58. & .header-tab-item{
  59. font-size: 14px;
  60. width: 100px;
  61. height: 80px;
  62. line-height: 80px;
  63. cursor: pointer;
  64. color: white;
  65. &.active{
  66. color: @primaryBlue;
  67. background-color: white;
  68. }
  69. }
  70. }
  71. }
  72. .header-container.offset{
  73. background-color: white;
  74. & .header-tab .header-tab-item {
  75. color: black;
  76. &.active {
  77. background-color: @primaryBlue;
  78. color: white;
  79. }
  80. }
  81. }
  82. </style>