adambard/learnxinyminutes-site

How about anchor navigation in code ?

Opened this issue · 0 comments

I suggest something like:

$(function() {

    if (location.hash.indexOf('code-') == 0) {
        $(document).scrollTop($(location.hash).offset().top);
    }

    $(".highlight > span").each(function(i) { 
        this.id = "code-"+i; 
    }).click(function() { 
        location.hash = this.id;
    });
});