原文:https://www . geeksforgeeks . org/如何在引导中为 scrollspy 设置偏移量属性/
偏移量是一个 Bootstrap Scrollspy 属性,其中用户可以指定在计算滚动位置时从顶部偏移的像素。当用户觉得导航条或列表很早就改变了状态,或者在冲浪时不需要时,它就变得很有用。它始终是一个数字,默认值为 10。该值可以通过 Javascript 或者将数据偏移值放入 body 标记中来更改。
语法:
正常申报
html
(body data-offset="")
Javascript 声明
```html
$(document).ready(function(){
$('body').scrollspy({target: " ", offset: });
});
```
示例 1: 该示例描述了使用了四个部分的引导导航栏,并且使用 Javascript 将 offset 属性设置为 60。
">
"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
Section 1
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
Section 2
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
Section 3
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
Section 4
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
GeeksforGeeks is a computer science
portal. It was created with a goal
in mind to provide well written, well
thought and well explained solutions
for selected questions. The core team
of five super geeks constituting of
technology lovers and computer science
enthusiasts have been constantly working
in this direction.
输出:
示例 2: 该示例描述了引导列表组,其中使用了三个部分,并且主体标签中的 offset 属性设置为 15。
">
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
"https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
data-target="#myScrollspy">
Bootstrap Scrollspy
Section One
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
Section Two
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
Section Three
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
GeeksforGeeks is a computer science portal. It was created with a goal
in mind to provide well written, well thought and well explained solutions
for selected questions. The core team of five super geeks constituting of
technology lovers and computer science enthusiasts have been constantly
working in this direction. GeeksforGeeks is a computer science portal.
It was created with a goal in mind to provide well written, well thought
and well explained solutions for selected questions. The core team of five
super geeks constituting of technology lovers and computer science
enthusiasts have been constantly working in this direction.
输出: