js實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡(jiǎn)單實(shí)例
如下所示:
<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層到頁(yè)面頂部的高度
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">《日常管理機(jī)制》</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)">第二章 分校運(yùn)營(yíng)管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第三章 分校人員管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第四章 品牌管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第五章 分校宣傳管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第六章 分校咨詢(xún)管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第七章 分校教學(xué)管理規(guī)定</a> </span> </li> <li> <span class="text-muted"> <a href="javascript:void(0)">第八章 增設(shè)分校的管理規(guī)定</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>
【效果預(yù)覽】

以上就是小編為大家?guī)?lái)的js實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡(jiǎn)單實(shí)例全部?jī)?nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
javascript在IE下trim函數(shù)無(wú)法使用的解決方法
這篇文章主要介紹了javascript在IE下trim函數(shù)無(wú)法使用的解決方法,分別敘述了javascript以及jQuery下的解決方案,對(duì)于WEB前端javascript設(shè)計(jì)人員進(jìn)行瀏覽器兼容性調(diào)試有不錯(cuò)的借鑒價(jià)值,需要的朋友可以參考下2014-09-09
JavaScript實(shí)現(xiàn)簡(jiǎn)單計(jì)時(shí)器
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)單計(jì)時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06
使用fabric實(shí)現(xiàn)恢復(fù)和撤銷(xiāo)功能的實(shí)例詳解
在圖形編輯器中,撤銷(xiāo)和恢復(fù)是一個(gè)非常常見(jiàn)的功能了,但是搜了下,網(wǎng)上好像也沒(méi)有太多相關(guān)的文章 可能是因?yàn)閏anvas相關(guān)的資料確實(shí)太少了吧,所以本文給大家介紹了如何基于 fabric 實(shí)現(xiàn)恢復(fù)、撤銷(xiāo)功能,需要的朋友可以參考下2024-06-06
JS簡(jiǎn)單實(shí)現(xiàn)仿百度控制臺(tái)輸出信息效果
這篇文章主要介紹了JS簡(jiǎn)單實(shí)現(xiàn)仿百度控制臺(tái)輸出信息效果,涉及javascript中console.log函數(shù)的簡(jiǎn)單使用技巧,需要的朋友可以參考下2016-09-09
JavaScript——DOM操作——Window.document對(duì)象詳解
下面小編就為大家?guī)?lái)一篇JavaScript——DOM操作——Window.document對(duì)象詳解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07
JS使用定時(shí)器與事件監(jiān)聽(tīng)實(shí)現(xiàn)輪播圖切換功能
現(xiàn)在很多網(wǎng)站都有輪播圖,下面這篇文章主要給大家介紹了關(guān)于JS如何使用定時(shí)器與事件監(jiān)聽(tīng)實(shí)現(xiàn)輪播圖切換功能的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
一文詳解如何在項(xiàng)目中和平時(shí)練習(xí)中應(yīng)用es6語(yǔ)法
ES6是JavaScript的一個(gè)版本,因?yàn)槲覀兦懊嬗玫降膙ue默認(rèn)使用ES6語(yǔ)法開(kāi)發(fā),所以我們?cè)谶@一節(jié)補(bǔ)充ES6的知識(shí)點(diǎn),下面這篇文章主要給大家介紹了關(guān)于如何在項(xiàng)目中和平時(shí)練習(xí)中應(yīng)用es6語(yǔ)法的相關(guān)資料,需要的朋友可以參考下2022-11-11

