这里有新鲜出炉的 Javascript 教程,程序狗速度看过来!
Javascript 是一种由 Netscape 的 LiveScript 发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如 Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
下面小编就为大家带来一篇 js 实现目录链接, 内容跟着目录滚动显示的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
如下所示:
- <script>
- require(["jquery", "bootstrap"],
- function($) {
- $(function() {
- $('.left').height(($('body').height() > $(window).height()) ? $('body').height() : $(window).height());
- });
- var goTo = $(".con");
- var guide = $(".sideGuide");
- var guideLi = $(".sideGuide li");
- var index = 0;
- var direct = 0;
- var goToFun = function() {
- var len = document.getElementById("box" + index).offsetTop - 30; //获取div层到页面顶部的高度
- direct = 0;
- if (index < 0) {
- index = 0;
- return;
- }
- if (index >= guideLi.size()) {
- index = guideLi.size() - 1;
- return;
- }
- $("html,.tree").stop().animate({
- scrollTop: len
- },
- 300, "swing",
- function() {
- direct = 0;
- });
- guideLi.removeClass("on").eq(index).addClass("on");
- }
- guideLi.each(function(i) {
- $(this).click(function() {
- index = guideLi.index($(this));
- goToFun();
- })
- });
- /* 滚轮事件 */
- var scrollFunc = function(e) {
- e = e || window.event;
- if (e.wheelDelta) {
- direct += ( - e.wheelDelta / 120);
- } else if (e.detail) {
- direct += e.detail / 3;
- }
- var first = document.getElementById("first").val();
- if (direct >= first) {
- goToFun(index++);
- }
- if (direct <= 0 - first) {
- goToFun(index--);
- }
- };
- });
- </script>
- <style>
- .return{padding-top:0.5em;}
- .title{text-align:center;font-weight:bold;padding-bottom:1em;border-bottom:2px solid #eee;line-height:1em;}
- .extend{text-align:center;color:#666;font-size:1.6em;line-height:3em;}
- .content{line-height:2.2em;}
- .content table{width:100%}
- .left{background-color:#fff;}
- .left .desc{color:#666;margin:2em 0;}
- .left .list{line-height:3em;}
- .left .list li{border-top: 1px solid #E4E1E1;}
- .href{cursor: pointer;}
- .lh2{line-height:2.4em;}
- .lh2 li{border-top: 1px solid #eee;}
- .tree{max-height:1000px;overflow-y: scroll;border: 1px solid #DDD;border-top: 0;border-left: 0;margin-top: 20px;}
- .sub-title{margin:2em auto 1em;text-align: center;font-size: 20px;}
- .on a{color:#000;font-weight: bold;}
- </style>
- <body style=" position:fixed;" ondragstart="return false" onselectstart="return false"
- onkeypress="return false" oncontextmenu="return false">
- <div class="container-fluid">
- <div class="text-right return">
- <a class="btn btn-default" href="javascript:history.back()">
- 返回
- </a>
- </div>
- <h2 class="title">
- 《日常管理机制》
- </h2>
- <div class="row">
- <div class="col-sm-3 hidden-xs left" style="height: 1193px;">
- <div class="container-fluid">
- <h3>
- 目录
- </h3>
- <div class="sideGuide">
- <ul class="list-unstyled lh2">
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第一章 总则
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第二章 分校运营管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第三章 分校人员管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第四章 品牌管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第五章 分校宣传管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第六章 分校咨询管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第七章 分校教学管理规定
- </a>
- </span>
- </li>
- <li>
- <span class="text-muted">
- <a href="javascript:void(0)">
- 第八章 增设分校的管理规定
- </a>
- </span>
- </li>
- <li>
- </li>
- </ul>
- </div>
- </div>
- </div>
- <div class="col-sm-9">
- <div class="container-fluid" style="background-color:#f5f5f5">
- <div class="tree mb40">
- <div id="box0" class="con">
- <div id="box1" class="con">
- <div id="box2" class="con">
- <div id="box3" class="con">
- <div id="box4" class="con">
- <div id="box5" class="con">
- <div id="box6" class="con">
- <div id="box7" class="con">
- </div>
- <input id="first" type="hidden" value="8">
- </div>
- </div>
- </div>
- </div>
- </body>
【效果预览】
以上就是小编为大家带来的 js 实现目录链接, 内容跟着目录滚动显示的简单实例全部内容了,希望大家多多支持 phperz~
来源: http://www.phperz.com/article/17/0710/331157.html