File tree Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Expand file tree Collapse file tree 1 file changed +28
-3
lines changed Original file line number Diff line number Diff line change 30
30
</div >
31
31
<prev-and-next v-if =" getResult" :prevInfo =" prevInfo" :nextInfo =" nextInfo" ></prev-and-next >
32
32
</div >
33
- <div class =" detail-content" >
34
- <div class =" article-content markdown-body" v-html =" handleDetail" ></div >
33
+ <div :class = " { 'fixed-toc-box': tocFixed } " class =" detail-content" >
34
+ <div ref = " articleContent " class =" article-content markdown-body" v-html =" handleDetail" ></div >
35
35
</div >
36
36
<prev-and-next v-if =" getResult" :prevInfo =" prevInfo" :nextInfo =" nextInfo" style =" padding : 15px ;" ></prev-and-next >
37
37
</el-main >
@@ -62,7 +62,8 @@ export default {
62
62
nextInfo: {},
63
63
authorInfo: {},
64
64
getResult: false ,
65
- clipboard: ' '
65
+ clipboard: ' ' ,
66
+ tocFixed: false
66
67
}
67
68
},
68
69
components: {
@@ -153,6 +154,10 @@ export default {
153
154
this .$message .error (' 复制成功失败' )
154
155
})
155
156
})
157
+ window .addEventListener (' scroll' , this .pageScroll , false )
158
+ },
159
+ beforeDestroy () {
160
+ window .removeEventListener (' scroll' , this .pageScroll , false )
156
161
},
157
162
methods: {
158
163
async apiArticleDetailMethod () {
@@ -189,6 +194,16 @@ export default {
189
194
})
190
195
this .info .articleStart = result .data .articleStart
191
196
}
197
+ },
198
+ pageScroll () {
199
+ if (document .querySelector (' .markdownIt-TOC' )) {
200
+ const pageScrollTop = document .documentElement .scrollTop
201
+ if (pageScrollTop >= 200 ) {
202
+ this .tocFixed = true
203
+ } else {
204
+ this .tocFixed = false
205
+ }
206
+ }
192
207
}
193
208
},
194
209
watch: {
@@ -219,6 +234,16 @@ export default {
219
234
line-height : 26px ;
220
235
}
221
236
}
237
+ .fixed-toc-box {
238
+ .markdownIt-TOC {
239
+ position : fixed ;
240
+ top : 80px ;
241
+ left : 50% ;
242
+ z-index : 100 ;
243
+ margin-left : 575px ;
244
+ max-width : 200px ;
245
+ }
246
+ }
222
247
.article-content {
223
248
font-size : 14px ;
224
249
color : #333 ;
You can’t perform that action at this time.
0 commit comments