Tocify是一个jQuery插件,能够动态的生成文章目录,Tocify可以随意的设置Twitter Bootstrap 或者 jQueryUI Themeroller支持的可选动画和jQuery的显示/隐藏效果,Tocify还支持平滑滚动,向前和向后按钮支持,可以监听浏览器的滚动显示当前的目录结构。

插件特点

  1. 主题支持 Twitter Bootstrap 或者 jQueryUI Themeroller 风格。

  2. 支持动态滚动和jQuery的点击显示/隐藏效果。

  3. 支持前进和后退按钮点击效果

  4. 支持平滑滚动动画效果

  5. 支持监听网页滚动事件,动态显示当前的目录结构。

  6. 支持页面扩展选项,确保一个页面有足够大的滚动表的所有内容项目

  7. 通过 jsHint 完美没有错误提示

在线实例

实例演示

使用方法

  1. <div id="toc"></div>
复制
  1. $(function() {
  2. //Calls the tocify method on your HTML div.
  3. $("#toc").tocify();
  4. });
复制

参数详解

选项 说明 默认值
context 任意可用的jQuery选择器 "body"
selectors 文章节点,可以关联生成目录 "h1,h2,h3"
showAndHide 是否展示二级目录结构 true
showEffect 目录展示效果:"none", "fadeIn", "show", or "slideDown" "slideDown"
showEffectSpeed 目录展示速度:"slow", "medium", "fast", 或数字(毫秒) "medium"
hideEffect 目录隐藏效果:"none", "fadeOut", "hide", "slideUp" "none"
hideEffectSpeed 目录隐藏速度:"slow", "medium", "fast", 或数字(毫秒) "medium"
smoothScroll 当点击目录节点菜单时,是否平滑滚动到文章对应的节点内容 true
smoothScrollSpeed 平滑滚动速率,可以是数字(毫秒) or String: "slow", "medium", or "fast" "medium"
scrollTo 当页面滚动时,页面顶端与目录之间的间隔 0
showAndHideOnScroll 当滚动页面时,是否显示和隐藏目录子菜单 true
theme 内容展示风格,可以是"bootstrap", "jqueryui", or "none" "bootstrap"
Name Type Default Options
context String “body” Any valid jQuery selector
selectors String “h1,h2,h3” Each comma separated selector must be a header element.
showAndHide Boolean true true or false
showEffect String “slideDown” “none”, “fadeIn”, “show”, or “slideDown”, or any of the other jQuery show effects
showEffectSpeed String or Number “medium” “slow”, “medium”, “fast”, or any numeric number (milliseconds)
hideEffect String “none” “none”, “fadeOut”, “hide”, “slideUp”, or any of the jQuery hide effects
hideEffectSpeed String or Number “medium” “slow”, “medium”, “fast”, or any numeric number (milliseconds)
smoothScroll Boolean true true or false
smoothScrollSpeed Number or String “medium” Accepts Number (milliseconds) or String: “slow”, “medium”, or “fast”
scrollTo Number or Function 0 Accepts any number (pixels) or Function
showAndHideOnScroll Boolean true true or false
highlightOnScroll Boolean true true or false
highlightOffset Number 40 Accepts any number (pixels)
theme String “bootstrap” “bootstrap”, “jqueryui”, or “none”
extendPage Boolean true true or false
extendPageOffset Number 100 Any number (pixels)
history Boolean true true or false
hashGenerator String or Function “compact” “compact”, “pretty”, function(text, element){}.
Compact – #CompressesEverythingTogether.
Pretty – #looks-like-a-nice-url-and-is-easily-readable.
function(text, element){} – Your own hash generation function that accepts the text as an argument, and returns the hash value.
highlightDefault Boolean true true or false
ignoreSelector String null Any valid jQuery selector
scrollHistory Boolean false true or false

设置参数

所有的选项可以设置插件时,称为。某些选项也可以设置插件后使用setoption()或setoptions()方法称为。

这里是设置一个选项的插件时,首先调用的一个例子:

  1. //Executes your code when the DOM is ready.  Acts the same as $(document).ready().
  2. $(function() {
  3. // Calls the selectBoxIt method on your HTML select box and updates the showEffect option
  4. var toc = $("#toc").tocify({ showEffect: "fadeIn" });
  5. });
复制

这里是设置一个选项的插件后首先调用使用SetOption方法的一个例子:

  1. //Executes your code when the DOM is ready.  Acts the same as $(document).ready().
  2. $(function() {
  3. // Calls the selectBoxIt method on your HTML select box
  4. var toc = $("#toc").tocify().data("toc-tocify");
  5. // Sets the smoothScroll option to false
  6. toc.setOption("showEffect", "fadeIn");
  7. });
复制

这里是设置多个选项的插件后首先调用使用setOptions方法的一个例子:

  1. //Executes your code when the DOM is ready.  Acts the same as $(document).ready().
  2. $(function() {
  3. // Calls the selectBoxIt method on your HTML select box and updates the showEffect option
  4. var toc = $("#toc").tocify().data("toc-tocify");
  5. // Sets the showEffect, scrollTo, and smoothScroll options
  6. toc.setOptions({ showEffect: "fadeIn", scrollTo: 50, smoothScroll: false });
  7. });
复制

获取参数

一个单一的选项可以通过使用option()方法检索。目前所有的选项可以通过引用选项属性检索。

这里是一个选项后检索插件使用option()方法称为例:

  1. //Executes your code when the DOM is ready.  Acts the same as $(document).ready().
  2. $(function() {
  3. //Calls the tocify method on your HTML div
  4. var toc = $("#toc").tocify().data("toc-tocify");
  5. // Writes the showEffect option to the console
  6. console.log(toc.option("showEffect"));
  7. });
复制

这里是检索所有当前选项的插件后利用期权特性称为例:

  1. //Executes your code when the DOM is ready.  Acts the same as $(document).ready().
  2. $(function() {
  3. //Calls the selectBoxIt method on your HTML select box
  4. var toc = $("#toc").tocify().data("toc-tocify");
  5. // Writes all of the current plugin options to the console
  6. console.log(toc.options);
  7. });
复制

jQuery Tocify 定位导航的更多相关文章

  1. [Jquery]网页定位导航特效

    描述:左右联动的导航,非常适合展示页面内容多,区块划分又很明显的,点击右边固定导航项时,左边的内容跟着切换.滑动滚动条的时候,右边的导航也随着左边的展示而进行高亮切换. 思路:比较滚动距离和楼层距离( ...

  2. jquery网页定位导航特效

    <!DOCTYPE html> <html lang="en"> <head> <script src="http://code ...

  3. JQuery和原生JavaScript实现网页定位导航特效

    慕课网的一个小课程,练习了一遍,不足之处,欢迎指正(照片在本地,大家可以着重看代码哈): <!DOCTYPE html> <html lang="en"> ...

  4. jQuery实现网页定位导航

    代码: <!doctype html> <html> <head> <meta charset="UTF-8"> <title ...

  5. jQuery实现页面导航内容定位效果,并支持内容切换

    需求 页面向下滚动时,需要将顶部的搜索栏信息和导航菜单吸顶,并且,搜索栏信息和导航菜单之间可以切换. 效果 https://www.iguopin.com/index.php?m=&c=ind ...

  6. css3圆环百分比,菜单栏定位导航

    前段时间,社区个人中心改版,看了下设计图,当时隐约感觉到有两个地方(圆环百分比,菜单栏定位导航)比较麻烦.设计图大致如下: 首先看圆环百分比,网上的做法大致分两种,一种是用了CSS3中的transfo ...

  7. 我收集到的最好的jQuery和CSS3导航菜单

    jQuery和CSS3导航菜单在网页设计和开发的重要组成部分之一.利用jQuery+CSS3实现可以做出拥有各种动画效果的漂亮菜单.在这里,我们收集了一些最好的jQuery+CSS3实现的导航菜单. ...

  8. 20款jquery下拉导航菜单特效代码分享

    20款jquery下拉导航菜单特效代码分享 jquery仿京东商城左侧分类导航下拉菜单代码 jQuery企业网站下拉导航菜单代码 jQuery css3黑色的多级导航菜单下拉列表代码 jquery响应 ...

  9. 利用js和JQuery定义一个导航条菜单

    利用js和JQuery定义一个导航条 效果: 一.html代码: <div class="Maintenance"> <div class="Title ...

随机推荐

  1. 数组的一个强大函数splice,[增,删,改]

    // var a = [1,2,3]; // a.splice(0); // console.log(a); >>[] // a.splice(1); // console.log(a); ...

  2. 构建自己的PHP框架--抽象Controller的基类

    上一篇博客中,我们将简单的路由解析和执行,从入口文件public/index.php中移入到框架中.入口文件顿时变得清爽无比-- 但是,去我们的controller里看一下,会看到如下的code: p ...

  3. Spring MVC 学习总结(五)——校验与文件上传

    Spring MVC不仅是在架构上改变了项目,使代码变得可复用.可维护与可扩展,其实在功能上也加强了不少. 验证与文件上传是许多项目中不可缺少的一部分.在项目中验证非常重要,首先是安全性考虑,如防止注 ...

  4. 漫谈可视化Prefuse(六)---改动源码定制边粗细

    可视化一路走来,体会很多:博客一路写来,收获颇丰:代码一路码来,思路越来越清晰.终究还是明白了一句古话:纸上得来终觉浅,绝知此事要躬行. 跌跌撞撞整合了个可视化小tool,零零碎碎结交了众多的志同道合 ...

  5. 16种基于 CSS3 & SVG 的创意的弹窗效果

    在去年,我给大家分享了<基于 CSS3 的精美模态窗口效果>,而今天我要与大家分享一些新鲜的想法.风格和趋势变化,要求更加适合现代UI的不同的效果.这组新模态窗口效果包含了一些微妙的动画, ...

  6. 【Android】Volley做网络请求的几种用法

    前言: 最近在将自己写的烂代码重构,以前使用的网络请求全是基于apache的HttpClient,简单使用还好,使用多了发现重复代码太多,而且每次使用都很繁琐,因此在网上找了半天网络请求的相关类库,最 ...

  7. UWP开发入门(二十三)——WebView

    本篇讨论在UWP开发中使用WebView控件时常见的问题,以及一些小技巧. WebView是实际开发中常用的控件,很多大家抱怨的套网页的应用都是通过WebView来实现的.这里要澄清一个问题,套网页的 ...

  8. cdh完美集成kafka

    前言 其实cloudera已经做了这个事了,只是把kafka的包和cdh的parcel包分离了,只要我们把分离开的kafka的服务描述jar包和服务parcel包下载了,就可以实现完美集成了. 具体实 ...

  9. [锋利的JQ]-超链接提示效果

    关键知识点: 1.事件对象:当事件一旦被触发,事件对象便会创立.事件对象只能作用于该事件的事件处理程序. 2.认识了mousemove事件了连续触发执行的特性. 代码: HTML: <div c ...

  10. 使用CKplayer插件在网页中嵌入视频的方法(常用笔记2)

    在做网站中有时候我们需要在网页中嵌入视频,一般视频嵌入有以下几种方法: 1. 优酷代码嵌入 优点:简单,方便,可靠. 缺点:有广告,现在的网站非常注重用户体验,如果打开一个在线视频是有长广告的一定会崩 ...