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 3030 </div >
3131 <prev-and-next v-if =" getResult" :prevInfo =" prevInfo" :nextInfo =" nextInfo" ></prev-and-next >
3232 </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 >
3535 </div >
3636 <prev-and-next v-if =" getResult" :prevInfo =" prevInfo" :nextInfo =" nextInfo" style =" padding : 15px ;" ></prev-and-next >
3737 </el-main >
@@ -62,7 +62,8 @@ export default {
6262 nextInfo: {},
6363 authorInfo: {},
6464 getResult: false ,
65- clipboard: ' '
65+ clipboard: ' ' ,
66+ tocFixed: false
6667 }
6768 },
6869 components: {
@@ -153,6 +154,10 @@ export default {
153154 this .$message .error (' 复制成功失败' )
154155 })
155156 })
157+ window .addEventListener (' scroll' , this .pageScroll , false )
158+ },
159+ beforeDestroy () {
160+ window .removeEventListener (' scroll' , this .pageScroll , false )
156161 },
157162 methods: {
158163 async apiArticleDetailMethod () {
@@ -189,6 +194,16 @@ export default {
189194 })
190195 this .info .articleStart = result .data .articleStart
191196 }
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+ }
192207 }
193208 },
194209 watch: {
@@ -219,6 +234,16 @@ export default {
219234 line-height : 26px ;
220235 }
221236}
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+ }
222247.article-content {
223248 font-size : 14px ;
224249 color : #333 ;
You can’t perform that action at this time.
0 commit comments