Last active
March 31, 2016 10:16
-
-
Save weaming/7e6cea5f484bb4be2587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
if ($("#toc").length == 0){ | |
console.log('#toc not found.'); | |
return 1; | |
} | |
$("h2,h3,h4,h5,h6").each(function(i,item){ | |
var tag = $(item).get(0).localName; | |
$(item).attr("id","toc"+i); | |
$("#toc").append('<a class="toc'+tag+'" href="#toc'+i+'">'+$(this).text()+'</a></br>'); | |
$(".toch2").css("margin-left",0); | |
$(".toch3").css("margin-left",20); | |
$(".toch4").css("margin-left",40); | |
$(".toch5").css("margin-left",60); | |
$(".toch6").css("margin-left",80); | |
}); | |
}); | |
</script> | |
<div id="toc"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment