gpt4 book ai didi

javascript - ScrollSpy 无法在我的网站上运行

转载 作者:行者123 更新时间:2023-11-28 04:10:43 26 4
gpt4 key购买 nike

我试图在我的网站中添加 scrollspy 东西,但目前还没有用。当我在那个部分时,它不会突出显示导航栏中的链接,这是 scrollspy 所做的,所以我无法找出问题所在。我已经粘贴了代码并帮助我弄清楚哪里出了问题。

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">

<!-- Navigation -->
<nav id="mainNav" class="navbar navbar-fixed-top">
<div class="container">
<a class="navbar-brand page-scroll" href="#page-top" style=" font-family: 'Lobster Two', cursive, serif;font-size:25px">my website</a>
<button class="btn btn-primary btn-toggle hidden-md-up float-xs-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">Menu <i class="fa fa-bars"></i></button>
<!-- Navigation Bar List Contents -->
<div class="clearfix hidden-md-up"></div>
<div class="collapse navbar-toggleable-sm" id="navbarResponsive">
<ul class="nav navbar-nav float-md-right">
<li class="nav-item">
<a class="nav-link page-scroll" href="#about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link page-scroll" href="#sample">Sample Article</a>
</li>
<li class="nav-item">
<a class="nav-link page-scroll" href="#topics">Topics</a>
</li>
<li class="nav-item">
<a class="nav-link page-scroll" href="#whyus">Why Choose Us</a>
</li>
<li class="nav-item">
<a class="nav-link page-scroll" href="#contact">Contact</a>
</li>
<li>
<a href="form.php" class="btn btn-md btn-info btn-block" role="button">Order now</a>
</li>
</ul>
</div>
</div>
</nav>

截面区域

   <!-- Start About Us Section -->
<section id="about">
<div class="container">
<div class="row">
<div class="col-lg-12 text-xs-center">
<h2 class="section-heading" style="color: black">About Us</h2>
</div>
</div>
<div class="row">
<div class="col-lg-12">
hello world
</div>
</div>
</div>
</section>
<!--End About Us-->

最佳答案

你没有显示你的 CSS,但我猜你没有设置 positionbodyrelative .

来自 Bootstrap's documentation :

No matter the implementation method, scrollspy requires the use of position: relative; on the element you’re spying on. In most cases this is the <body>. When scrollspying on elements other than the <body>, be sure to have a height set and overflow-y: scroll; applied.

关于javascript - ScrollSpy 无法在我的网站上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42734386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com