一个轻量级的jQuery&Bootstrap 5/4/3插件,用于从文档中的标题标签生成一个粘性的、可折叠的目录。就像你在Bootstrap文档网站上看到的侧边栏内容导航一样
1.在头中加载bootstrap-toc.css样式表,在文档末尾加载bootstrap-toc.js脚本。
<link rel="stylesheet" href="/path/to/bootstrap.min.css"> <link href="bootstrap-toc.css" rel="stylesheet"> ... <script src="/path/to/jquery.min.js"></script> <script src="/path/to/bootstrap.min.js"></script> <script src="bootstrap-toc.js"></script>
2.创建一个空导航
目录的元素。
<nav id="toc" data-spy="affix" data-toggle="toc"></nav>
3.添加以下内容数据
属性到身体
滚动间谍支持的标签。
<body data-spy="scroll" data-target="#toc">
4.就是这样。插件会自动在导航
要素您也可以通过JavaScript初始化插件,如下所示。
$(function() { var $myToc = $('...'); Toc.init($myToc); $('body').scrollspy({ target: $myNav }); });
5.指定将限制搜索标题的元素
Toc.init({ // The element that the navigation will be created in $nav: $('#myToc'), // The element where the search for headings will be limited to $scope: $(document.body) });
2022-05-23
v1.0.1 (2019-01-09)
v1.0.0 (2018-07-27)
2015-12-13
2015-12-13