detail.vue
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<template>
<div class="home-wrapper">
<div class="home-body">
<router-view></router-view>
<div class="side-wrapper">
<side-article :sideClassify="BROWSE_STATUS"></side-article>
<side-article
:sideClassify="RECOMMEND_STATUS"
:class="{ 'side-sticky': showSide && showSticky }"
></side-article>
<label-classify
:class="[showSide && showSticky ? 'label-sticky' : 'side-sticky']"
></label-classify>
</div>
</div>
</div>
</template>
<script>
import SideArticle from "components/sideArticle";
import { BROWSE_STATUS, RECOMMEND_STATUS } from "src/constant/side";
import DetailContent from "./components/detailContent";
import LabelClassify from "components/labelClassify";
export default {
name: "labelComponent",
components: {
SideArticle,
DetailContent,
LabelClassify,
},
props: {},
computed: {},
data() {
return {
BROWSE_STATUS,
RECOMMEND_STATUS,
scrollTop: 0,
showSticky: false,
showSide: true,
};
},
watch: {},
created() { },
mounted() {
const clientHeight = document.documentElement.clientHeight;
this.showSide = clientHeight > 840; // 840 = 665 + 170(label分类高度) + 之间间距
window.addEventListener("scroll", this.handleScroll);
},
beforeDestroy() {
window.removeEventListener("scroll", this.handleScroll);
},
methods: {
handleScroll() {
this.scrollTop =
document.documentElement.scrollTop || document.body.scrollTop;
this.showSticky = this.scrollTop > 665; // 665是一个side-article组件的高度
},
},
};
</script>
<style lang="less" scoped>
.side-sticky {
position: sticky;
top: 0;
}
.label-sticky {
position: sticky;
top: 665px;
}
</style>