feat:实现滚动时自动定位TOC

pull/358/head
lifei6671 2018-09-12 11:19:45 +08:00
parent 7e05c18c29
commit 5a54cba310
2 changed files with 23 additions and 2 deletions

View File

@ -57,7 +57,7 @@
border-right: 2px solid #25b864;
}
.article-body .markdown-article{
.article-body .markdown-article,.article-body .attach-list{
margin-right: 200px;
}
.markdown-toc-list .directory-item {
@ -93,7 +93,7 @@
padding-left: 4.8em;
}
.markdown-toc-list .directory-item-active {
border-left: 2px solid #25b864;
border-left: 2px solid #25b864 !important;
}
.markdown-toc-list .directory-item-active a {
color: #25b864;

View File

@ -288,6 +288,27 @@ $(function () {
return $(body).highlight(window.keyword);
});
});
$(".manual-right").scroll(function(){
var scrollTop = $(document).scrollTop();
var oItem = $(".markdown-heading").find(".reference-link");
var oName = "";
$.each(oItem,function(){
var oneItem = $(this);
var offsetTop = oneItem.offset().top;
if(offsetTop-scrollTop < 200){
oName = "#" + oneItem.attr("name");
}
});
console.log(oName);
$(".markdown-toc-list a").each(function () {
if(oName === $(this).attr("href")) {
$(this).parents("li").addClass("directory-item-active");
}else{
$(this).parents("li").removeClass("directory-item-active");
}
});
});
});
</script>
{{.Scripts}}