|
1 | 1 | <template> |
2 | | - <div class="home-view" :class="{'home-view-docs': isDocs}"> |
3 | | - <div class="navigator" :class="{ active: showTabs }"> |
| 2 | + <div class="home-view" :class="{'home-view-docs': isDocs, 'home-view-demo': isExample, opacity1: opacity1}"> |
| 3 | + <div class="navigator" ref="navigator" :class="{ active: showTabs }"> |
4 | 4 | <div class="logo"> |
5 | 5 | <router-link to="/"><img src="./didi-logo.svg" alt="DiDi"></router-link> |
6 | 6 | </div> |
|
21 | 21 | <script> |
22 | 22 | import Lang from '../lang/lang.vue' |
23 | 23 | import NavLoading from '../nav-loading/nav-loading.vue' |
| 24 | + import throttle from 'lodash-es/throttle' |
| 25 | +
|
24 | 26 | export default { |
25 | 27 | data() { |
26 | 28 | return { |
27 | 29 | showTabs: false, |
28 | | - isDocs: this.$route.path.indexOf('/docs') > -1 |
| 30 | + opacity1: false, |
| 31 | + isDocs: this.$route.path.indexOf('/docs') > -1, |
| 32 | + isExample: this.$route.path.indexOf('/example') > -1 |
| 33 | + } |
| 34 | + }, |
| 35 | + computed: { |
| 36 | + isIndex() { |
| 37 | + return !this.isDocs && !this.isExample |
29 | 38 | } |
30 | 39 | }, |
31 | 40 | watch: { |
32 | 41 | $route(val) { |
33 | 42 | this.isDocs = val.path.indexOf('/docs') > -1 |
| 43 | + this.isExample = val.path.indexOf('/example') > -1 |
34 | 44 | this.showTabs = false |
| 45 | + }, |
| 46 | + isIndex: { |
| 47 | + handler: function (newVal) { |
| 48 | + if (newVal) { |
| 49 | + document.addEventListener('touchmove', this.checkScrollTop, false) |
| 50 | + window.addEventListener('scroll', this.checkScrollTop, false) |
| 51 | + } else { |
| 52 | + document.removeEventListener('touchmove', this.checkScrollTop, false) |
| 53 | + window.removeEventListener('scroll', this.checkScrollTop, false) |
| 54 | + this.$refs.navigator && (this.$refs.navigator.style.backgroundColor = '') |
| 55 | + } |
| 56 | + }, |
| 57 | + immediate: true |
35 | 58 | } |
36 | 59 | }, |
| 60 | + beforeCreate() { |
| 61 | + this.checkScrollTop = throttle(() => { |
| 62 | + const y = window.scrollY |
| 63 | + const h = 48 |
| 64 | + const opacity = y / h |
| 65 | + this.opacity1 = opacity >= 0.98 |
| 66 | + this.$refs.navigator.style.backgroundColor = `rgba(255, 255, 255, ${opacity})` |
| 67 | + }, 10, { |
| 68 | + leading: true |
| 69 | + }) |
| 70 | + }, |
| 71 | + mounted() { |
| 72 | + setTimeout(() => { |
| 73 | + this.isIndex && this.checkScrollTop() |
| 74 | + }) |
| 75 | + }, |
37 | 76 | components: { |
38 | 77 | SiteLang: Lang, |
39 | 78 | NavLoading |
|
58 | 97 | transition: all 250ms ease |
59 | 98 | @media screen and (max-width: 960px) |
60 | 99 | padding-top: 48px |
61 | | - &.home-view-docs |
| 100 | + &.home-view-docs, &.home-view-demo |
62 | 101 | overflow: hidden |
63 | 102 | height: auto |
64 | 103 | .toggle-nav |
65 | 104 | display: none!important |
66 | 105 | .router-view |
67 | 106 | height: 100% |
| 107 | + .home-view-docs, .home-view-demo, .opacity1 |
| 108 | + .navigator |
| 109 | + box-shadow: 0 1px 2px rgba(0, 0, 0, .15) |
68 | 110 | .navigator |
69 | | - position: relative |
| 111 | + z-index: 5 |
| 112 | + position: fixed |
| 113 | + top: 0 |
| 114 | + left: 0 |
| 115 | + right: 0 |
70 | 116 | height: 70px |
71 | 117 | line-height: 70px |
72 | 118 | padding: 0 100px |
73 | | - margin-top: -70px |
74 | | - transition: all 0.3s ease |
| 119 | + margin-top: 0 |
| 120 | + background-color: #fff |
75 | 121 | @media screen and (max-width: 960px) |
76 | 122 | padding: 0 |
77 | 123 | height: 48px |
78 | 124 | line-height: 48px |
79 | | - margin-top: -48px |
80 | 125 | &.active |
81 | 126 | .tabs |
82 | 127 | transition: transform .2s |
|
111 | 156 | float: left |
112 | 157 | padding: 0 16px |
113 | 158 | height: 100% |
| 159 | + a |
| 160 | + display: block |
| 161 | + height: 100% |
| 162 | + margin: 0 80px |
114 | 163 | @media screen and (max-width: 960px) |
115 | 164 | float: none |
116 | 165 | text-align: center |
|
123 | 172 | padding: 0 30px |
124 | 173 | box-shadow: none |
125 | 174 | @media screen and (max-width: 960px) |
126 | | - position: absolute |
| 175 | + position: fixed |
127 | 176 | z-index: 10 |
128 | 177 | right: 10px |
129 | 178 | padding: 0 0 0 2px |
|
161 | 210 | transition: color .2s |
162 | 211 | @media screen and (max-width: 960px) |
163 | 212 | display: block |
164 | | - line-height: 36px |
| 213 | + line-height: 45px |
165 | 214 | color: black |
166 | 215 | &:hover |
167 | 216 | color: $color-orange |
|
0 commit comments