Bootstrap Scrollspy源碼學(xué)習(xí)
本文實(shí)例為大家分享了Bootstrap Scrollspy插件的具體代碼,供大家參考,具體內(nèi)容如下
導(dǎo)航欄Scrollspy例子
<!-- The scrollable area --> <body data-spy="scroll" data-target=".navbar" data-offset="50"> <!-- The navbar - The <a> elements are used to jump to a section in the scrollable area --> <nav class="navbar navbar-inverse navbar-fixed-top"> ... <ul class="nav navbar-nav"> <li><a href="#section1" rel="external nofollow" rel="external nofollow" >Section 1</a></li> ... </nav> <!-- Section 1 --> <div id="section1"> <h1>Section 1</h1> <p>Try to scroll this page and look at the navigation bar while scrolling!</p> </div> ... </body>
垂直Scrollspy例子
<body data-spy="scroll" data-target="#myScrollspy" data-offset="20"> <div class="container"> <div class="row"> <nav class="col-sm-3" id="myScrollspy"> <ul class="nav nav-pills nav-stacked"> <li><a href="#section1" rel="external nofollow" rel="external nofollow" >Section 1</a></li> ... </ul> </nav> <div class="col-sm-9"> <div id="section1"> <h1>Section 1</h1> <p>Try to scroll this page and look at the navigation list while scrolling!</p> </div> ... </div> </div> </div> </body>
Scrollspy的使用
使用Scrollspy只需在對(duì)應(yīng)的HTML元素里添加幾個(gè)關(guān)鍵的屬性:
- data-spy=”scroll”
添加到需要滾動(dòng)的元素中,比如最常見的body元素,或者container。
- data-target=”selector”
添加到需要滾動(dòng)的元素中,selector指示的是控制滾動(dòng)的元素比如”.navbar”, “#myScrollspy”。
- <a href=”#section”>section</a>
在控制滾動(dòng)的元素中用link鏈接到對(duì)應(yīng)的位置。注意鏈接的id要跟對(duì)應(yīng)位置元素的id相匹配。例如,<div id=”section1”>與<a href=”#seciton1”。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
不刷新網(wǎng)頁(yè)就能鏈接新的js文件方法總結(jié)
在本篇文章里小編給大家整理的是關(guān)于不刷新網(wǎng)頁(yè)就能鏈接新的js文件方法總結(jié),需要的朋友們參考下。2020-03-03原生JavaScript實(shí)現(xiàn)合并多個(gè)數(shù)組示例
這篇文章主要介紹了原生的JavaScript及jquery實(shí)現(xiàn)合并多個(gè)數(shù)組,很簡(jiǎn)單,很實(shí)用,大家可以看看2014-09-09一文詳解Proxy和Object.defineProperty的使用與區(qū)別
在JavaScript中,對(duì)象是一種核心的數(shù)據(jù)結(jié)構(gòu),而對(duì)對(duì)象的操作也是開發(fā)中經(jīng)常遇到的任務(wù),本文將深入比較Proxy和Object.defineProperty,感興趣的小伙伴可以了解下2023-12-12javascript實(shí)現(xiàn)簡(jiǎn)單的二級(jí)聯(lián)動(dòng)
這篇文章主要介紹了javascript實(shí)現(xiàn)簡(jiǎn)單的二級(jí)聯(lián)動(dòng),非常的實(shí)用,需要的朋友可以參考下2015-03-03JavaScript 事件監(jiān)聽實(shí)例代碼[兼容IE,firefox] 含注釋
JavaScript事件監(jiān)聽完整實(shí)例 含注釋,非常的不錯(cuò),大家可以直接使用。2009-08-08微信小程序?qū)崿F(xiàn)音頻文件播放進(jìn)度的實(shí)例代碼
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)音頻文件播放進(jìn)度的實(shí)例代碼,代碼包括對(duì)進(jìn)度條的實(shí)現(xiàn)及進(jìn)度條的滑動(dòng),對(duì)大家的工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03js完美解決IE6不支持position:fixed的bug
關(guān)于IE6,雖然它已被微軟拋棄很久了,但是由于大天朝的特殊行情(盜版)對(duì)于前端工程師來(lái)說(shuō),解決IE6兼容position:fixed的問(wèn)題顯得很重要。特別是你需要用到頭尾懸停調(diào)用的時(shí)候2015-04-04