我在我的项目中使用了ng-bootstrap [ngbScrollSpy]
指令,就像在the documentation中提到的那样,但它不起作用-在滚动上,活动项没有改变.
我的代码如下:
<div>
<div class="sticky-top">
<ul class="nav menu-sidebar">
<li >
<a [ngbScrollSpyItem]="[spy, 'about']">About</a>
</li>
<li >
<a [ngbScrollSpyItem]="spy" fragment="schedule">Schedule</a>
</li>
<li >
<a [ngbScrollSpyItem]="spy" fragment="hotel">Information about the hotel</a>
</li>
</ul>
</div>
<div ngbScrollSpy #spy="ngbScrollSpy" >
<section ngbScrollSpyFragment="about">
<h3>About</h3>
<p>{{some long long text and content}}</p>
</section>
<section ngbScrollSpyFragment="schedule">
<h3>Schedule</h3>
<p>{{some long long text and content}}</p>
</section>
<section ngbScrollSpyFragment="hotel">
<h3>Information about the hotel</h3>
<p>{{some long long text and content}}</p>
</section>
</div>
</div>
我看到in this stackoverflow question,我的问题是我没有向div提供height
,这是真的.
但我的卷轴间谍部分遍布整个页面,而不是一个小部分(NAV本身就是sticky-top
).所以我不能给它高度.
我知道还有另一种方法-刷新窗口滚动上的Scrollspy,但我找不到正确的代码来帮助我.
你能解决我的问题吗? 为我提供刷新滚动的代码spy/给我有关高度的提示/帮助我找到另一个相应的元素.
非常感谢!
将链接附加到stackblitz demo