Bootstrap Scrollspy源碼學習
本文實例為大家分享了Bootstrap Scrollspy插件的具體代碼,供大家參考,具體內容如下
導航欄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只需在對應的HTML元素里添加幾個關鍵的屬性:
- data-spy=”scroll”
添加到需要滾動的元素中,比如最常見的body元素,或者container。
- data-target=”selector”
添加到需要滾動的元素中,selector指示的是控制滾動的元素比如”.navbar”, “#myScrollspy”。
- <a href=”#section”>section</a>
在控制滾動的元素中用link鏈接到對應的位置。注意鏈接的id要跟對應位置元素的id相匹配。例如,<div id=”section1”>與<a href=”#seciton1”。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
一文詳解Proxy和Object.defineProperty的使用與區(qū)別
在JavaScript中,對象是一種核心的數據結構,而對對象的操作也是開發(fā)中經常遇到的任務,本文將深入比較Proxy和Object.defineProperty,感興趣的小伙伴可以了解下2023-12-12JavaScript 事件監(jiān)聽實例代碼[兼容IE,firefox] 含注釋
JavaScript事件監(jiān)聽完整實例 含注釋,非常的不錯,大家可以直接使用。2009-08-08js完美解決IE6不支持position:fixed的bug
關于IE6,雖然它已被微軟拋棄很久了,但是由于大天朝的特殊行情(盜版)對于前端工程師來說,解決IE6兼容position:fixed的問題顯得很重要。特別是你需要用到頭尾懸停調用的時候2015-04-04