-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhands-on-docinfo-footer.html
35 lines (33 loc) · 1.15 KB
/
hands-on-docinfo-footer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script type="text/javascript">
var tocitems = $('#toc li a'),
scrollItems = tocitems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
$(document).ready(function() {
var lastId
$(window).scroll(function() {
// Get container scroll position
var fromTop = $(this).scrollTop();
// Get id of current scroll item
var cur = scrollItems.map(function(){
var offset = this.offset().top - parseFloat(this.css('margin-top'))
if (offset < fromTop) {
return this;
}
});
// Get the id of the current element
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
// Set/remove active class
scrollItems
.end().parent()
.removeClass("active")
.end().filter("[href='#"+id+"']")
.parent().addClass("active");
}
} );
} );
</script>