Git Product home page Git Product logo

katelog's Introduction

文章目录自动生成器

类似于segmentfault和掘金的文章目录,无第三方依赖的,自动生成文章目录结构,灵活配置

demo地址

npm引入

npm i katelog -S

es6使用

import katelog from 'katelog';
console.log(katelog);

html引入

<!-- 引入js文件 -->
<script src='./katelog.min.js'></script>
<!-- 文章容器 -->
<div id="kCatelog"></div>
<!-- 目录容器 -->
<div class="k-catelog-list" id="catelogList"></div>
new katelog({
    contentEl: 'kCatelog',
    catelogEl: 'catelogList',
    linkClass: 'k-catelog-link',
    linkActiveClass: 'k-catelog-link-active',
    supplyTop: 20,
    selector: ['h2', 'h3'],
    active: function (el) {
        console.log(el);
    }
});

仅支持IE8以上和主流的浏览器

选项

contentEl

文章容器,id选择器

catelogEl

目录容器,id选择器

linkClass

每个目录项的类

linkActiveClass

当前激活的目录项的类

selector(可选)

选择目录的标题元素,默认支持6级树形结构

默认值: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']

selector: ['h2', 'h3']
supplyTop(可选)

每个目录需要补充的高度,比如fixed头部布局会挡住实现,可以设置supplyTop来修正

方法

rebuild()

动态新增或者删除的内容,重新构建目录

let katelog = new katelog({ ... });
katelog.rebuild();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.