learnxinyminutes-site icon indicating copy to clipboard operation
learnxinyminutes-site copied to clipboard

How about anchor navigation in code ?

Open dangreen opened this issue 9 years ago • 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;
    });
});

dangreen avatar Feb 13 '16 13:02 dangreen