Scrollspy Bootstrap 4 - 不在Codepen上

时间:2017-09-11 05:47:08

标签: html bootstrap-4 scrollspy codepen

我正在尝试为我的投资组合页面使用Bootstrap 4 Scrollspy功能,但我无法在Codepen中使用它。

我在StackOverflow中搜索过,发现有人在Codeply中使用了这个功能,here’s the link,它运行得很好。

我接受了代码并将其放在Codepen上,但无法使其正常工作:here’s the link。这是HTML。

<body data-spy="scroll" data-target="#navbarCodeply" data-offset="70">
 <nav class="navbar navbar-expand-md fixed-top navbar-light bg-light">
    <div class="container">
      <a class="navbar-brand" href="#">Codeply</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCodeply">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarCodeply">
        <ul class="nav navbar-nav">
            <a class="nav-link" href="#sec1">One</a>
            <a class="nav-link" href="#sec2">Two</a>
            <a class="nav-link" href="#sec3">Three</a>
        </ul>
      </div>
    </div>
 </nav>
 <div class="container">
   <h6 class="mb-5">Bootstrap 4 Scrollspy Example</h6>
   <div class="row">
     <div class="col-12 col-sm-8">
        <h3 id="sec1">One</h3>
        <p>Sriracha biodiesel taxidermy organic post-ironic, Intelligentsia salvia mustache 90's code editing brunch. Butcher polaroid VHS art party, hashtag Brooklyn deep v PBR narwhal sustainable mixtape swag wolf squid tote bag. Tote bag cronut semiotics,
            raw denim deep v taxidermy messenger bag. Tofu YOLO Etsy, direct trade ethical Odd Future jean shorts paleo. Forage Shoreditch tousled aesthetic irony, street art organic Bushwick artisan cliche semiotics ugh synth chillwave meditation.
            Shabby chic lomo plaid vinyl chambray Vice. Vice sustainable cardigan, Williamsburg master cleanse hella DIY 90's blog.</p>

        <p>Ethical Kickstarter PBR asymmetrical lo-fi. Dreamcatcher street art Carles, stumptown gluten-free Kickstarter artisan Wes Anderson wolf pug. Godard sustainable you probably haven't heard of them, vegan farm-to-table Williamsburg slow-carb
            readymade disrupt deep v. Meggings seitan Wes Anderson semiotics, cliche American Apparel whatever. Helvetica cray plaid, vegan brunch Banksy leggings +1 direct trade. Wayfarers codeply PBR selfies. Banh mi McSweeney's Shoreditch selfies,
            forage fingerstache food truck occupy YOLO Pitchfork fixie iPhone fanny pack art party Portland.</p>
        <hr>
        <h3 id="sec2">Two</h3>
        <p>Sriracha biodiesel taxidermy organic post-ironic, Intelligentsia salvia mustache 90's code editing brunch. Butcher polaroid VHS art party, hashtag Brooklyn deep v PBR narwhal sustainable mixtape swag wolf squid tote bag. Tote bag cronut semiotics,
            raw denim deep v taxidermy messenger bag. Tofu YOLO Etsy, direct trade ethical Odd Future jean shorts paleo. Forage Shoreditch tousled aesthetic irony, street art organic Bushwick artisan cliche semiotics ugh synth chillwave meditation.
            Shabby chic lomo plaid vinyl chambray Vice. Vice sustainable cardigan, Williamsburg master cleanse hella DIY 90's blog.</p>

        <p>Ethical Kickstarter PBR asymmetrical lo-fi. Dreamcatcher street art Carles, stumptown gluten-free Kickstarter artisan Wes Anderson wolf pug. Godard sustainable you probably haven't heard of them, vegan farm-to-table Williamsburg slow-carb
            readymade disrupt deep v. Meggings seitan Wes Anderson semiotics, cliche American Apparel whatever. Helvetica cray plaid, vegan brunch Banksy leggings +1 direct trade. Wayfarers codeply PBR selfies. Banh mi McSweeney's Shoreditch selfies,
            forage fingerstache food truck occupy YOLO Pitchfork fixie iPhone fanny pack art party Portland.</p>
        <h3 id="sec3">Three</h3>
        <p>Sriracha biodiesel taxidermy organic post-ironic, Intelligentsia salvia mustache 90's code editing brunch. Butcher polaroid VHS art party, hashtag Brooklyn deep v PBR narwhal sustainable mixtape swag wolf squid tote bag. Tote bag cronut semiotics,
            raw denim deep v taxidermy messenger bag. Tofu YOLO Etsy, direct trade ethical Odd Future jean shorts paleo. Forage Shoreditch tousled aesthetic irony, street art organic Bushwick artisan cliche semiotics ugh synth chillwave meditation.
            Shabby chic lomo plaid vinyl chambray Vice. Vice sustainable cardigan, Williamsburg master cleanse hella DIY 90's blog.</p>

        <p>Ethical Kickstarter PBR asymmetrical lo-fi. Dreamcatcher street art Carles, stumptown gluten-free Kickstarter artisan Wes Anderson wolf pug. Godard sustainable you probably haven't heard of them, vegan farm-to-table Williamsburg slow-carb
            readymade disrupt deep v. Meggings seitan Wes Anderson semiotics, cliche American Apparel whatever. Helvetica cray plaid, vegan brunch Banksy leggings +1 direct trade. Wayfarers codeply PBR selfies. Banh mi McSweeney's Shoreditch selfies,
            forage fingerstache food truck occupy YOLO Pitchfork fixie iPhone fanny pack art party Portland.</p>
    </div>
  </div>

这就是CSS。

body {
  position: relative;
  overflow-y: auto;
  padding-top: 70px; /* padding for fixed navbar */
}

正如您所看到的,当您在Codepen中向下滚动时,导航项不会更改,但在Codeply中它们会更改。

有谁知道什么是错的?

提前感谢您的帮助。

Juan Betancourt。

PS:我认为问题可能出在CSS和JavaScript Pen设置或body标签属性中。

1 个答案:

答案 0 :(得分:0)

Bootstrap 4需要Popper.js ..

/popper.js/1.11.0/umd/popper.min.js

Codeply在您选择“Bootstrap 4”时自动包含它,但codepen没有。