Bootstrap Scrollspy源码学习
2019/6/27 21:07:41
本文主要是介绍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”。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
这篇关于Bootstrap Scrollspy源码学习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-20Vue资料入门教程:从零开始学习Vue.js
- 2024-09-20Vuex4入门教程:轻松掌握Vue状态管理
- 2024-09-20Element-Plus入门指南:轻松构建美观的Vue组件
- 2024-09-20VueRouter4入门教程:轻松掌握Vue路由
- 2024-09-20Vuex4入门教程:轻松掌握Vue状态管理
- 2024-09-20Vue3课程:新手入门与初级教程详解
- 2024-09-20Vue3课程:新手入门到初级实战指南
- 2024-09-20Vuex4学习:一步一步搭建你的第一个Vuex状态管理库
- 2024-09-19Vue项目中实现TagsView标签栏导航的简单教程
- 2024-09-19Vue3入门指南:基础教程与实战项目