Skip to content

Commit 7e33e0e

Browse files
committed
优化
1 parent d15a846 commit 7e33e0e

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

src/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,9 @@ export default {
117117
footer {
118118
margin-top: 100px;
119119
}
120+
121+
#app,
122+
main {
123+
position: relative;
124+
}
120125
</style>

src/components/header.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ export default {
107107
height: 60px;
108108
align-items: center;
109109
padding: 10px 100px;
110-
position: relative;
110+
// position: relative;
111111
z-index: 1000;
112112
&.fixedToTop {
113113
position: fixed;
114-
114+
115115
width: 100%;
116116
}
117117
&.main-color {

src/helper/utilities.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ export function formatDate(date, format = true) {
5757

5858
return format ? `${Y}-${M}-${d} ${h}:${m}:${s}` : `${Y}-${M}-${d}`;
5959
}
60+
61+
export function getOffsetTop(relativeNode, node, topSum = 0) {
62+
topSum += node.offsetTop;
63+
64+
if (node.offsetParent !== relativeNode) {
65+
return getOffsetTop(relativeNode, node.offsetParent, topSum);
66+
}
67+
return topSum;
68+
}

src/views/Jobs.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
<!-- 搜索 -->
66
<div ref="searchBar" :class="{ fixedTop: searchBarFixedTop }" class="search-wrapper">
7-
<input-search placeholder="搜索职位" v-model="searchKeyword"></input-search>
7+
<input-search
8+
:size="searchBarFixedTop?'small':'medium'"
9+
placeholder="搜索职位"
10+
v-model="searchKeyword"
11+
></input-search>
812
</div>
913

1014
<div class="main clearfix">
@@ -61,6 +65,7 @@
6165
</div>
6266
</template>
6367
<script>
68+
import { getOffsetTop } from "@/helper/utilities";
6469
let positionY = 0;
6570
let searchBarClientHeight = 0;
6671
@@ -106,13 +111,13 @@ export default {
106111
},
107112
mounted() {
108113
this.$nextTick(() => {
109-
positionY = this.$refs.searchBar.offsetTop;
114+
positionY = getOffsetTop(document.body, this.$refs.searchBar);
110115
searchBarClientHeight = this.$refs.searchBar.clientHeight;
116+
111117
});
112118
},
113119
activated() {
114120
const onPageScroll = () => {
115-
116121
const top = this.$refs.searchBar.getBoundingClientRect().top;
117122
118123
this.searchBarFixedTop =

0 commit comments

Comments
 (0)