Skip to content

Commit aea64b6

Browse files
authored
Merge pull request pytorch#679 from shiftlab/contributor-scroll-nav
Contributors - Left Nav - Highlight as user scrolls
2 parents dd0084a + 5c8df33 commit aea64b6

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

_includes/contributor_side_nav.html

+37
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,40 @@
1010
</ul>
1111
</div>
1212
</div>
13+
14+
<script>
15+
16+
$("#get-started-contributor-sidebar-list li a").on("click", function(e) {
17+
var href = $(this).attr("href")
18+
$('html, body').stop().animate({
19+
scrollTop: $(href).offset().top - 100
20+
}, 850);
21+
(e).preventDefault;
22+
});
23+
24+
var lastId,
25+
topMenu = $("#get-started-contributor-sidebar-list"),
26+
topMenuHeight = topMenu.outerHeight() + 1,
27+
// All sidenav items
28+
menuItems = topMenu.find("a"),
29+
// Anchors for menu items
30+
scrollItems = menuItems.map(function() {
31+
var item = $(this).attr("href");
32+
if (item.length) { return item; }
33+
});
34+
35+
$(window).scroll(function(){
36+
var fromTop = $(this).scrollTop()+topMenuHeight;
37+
var article = '.pytorch-article'
38+
39+
$(article).each(function(i){
40+
var offsetScroll = $(this).offset().top-$(window).scrollTop();
41+
if (offsetScroll <= topMenuHeight + 200 && offsetScroll >= topMenuHeight - 200 && scrollItems[i] == "#" + $(this).children().attr("id") && $(".hidden:visible")) {
42+
$(menuItems).removeClass("active");
43+
$(menuItems[i]).addClass("active");
44+
}
45+
})
46+
});
47+
48+
</script>
49+
<script src="https://code.jquery.com/jquery-migrate-3.0.0.min.js"></script>

0 commit comments

Comments
 (0)