Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我在原来的基础上加了上下滑动时候,目录对应的标题高亮的效果,希望作者整合代码 #44

Open
code906 opened this issue Nov 7, 2019 · 1 comment

Comments

@code906
Copy link

code906 commented Nov 7, 2019

具体这样做的。
在原来的基础上添加,当滑动到对应的标题时候,目录对应添加class属性read
.esa-catalog-contents .read{
color: #e06c75;
}

下面是js代码

<script type="text/javascript"> function showArticleIndex() { var anchorList = $(".esa-anchor"); // 监听浏览器滚动条,当浏览过的标签,给他上色。 $(window).on("scroll", function(e){ var windowTop = $(window).scrollTop(); anchorList.each(function(item, index){ var anchorTop = $(this).offset().top; var node = $(this).attr("href").replace(/^#/gi,''); var tocLink = $('.esa-catalog-contents ul i[class=' + node + ']'); if ( anchorTop <= windowTop+200 ) { tocLink.parent("li").addClass("read"); } else { tocLink.parent("li").removeClass("read"); } }); }); } showArticleIndex(); </script>
@code906
Copy link
Author

code906 commented Nov 7, 2019

效果如我的博客:
https://www.cnblogs.com/code609/p/11807231.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant