Scrollspy Bootstrap 4 - Not working on Codepen

600 views Asked by At

I’m trying to use the Bootstrap 4 Scrollspy feature for my Portfolio Page, but I can’t make it work in Codepen.

I searched in StackOverflow and found that someone used this feature in Codeply, here’s the link, and it works just fine.

I took the code and put it on Codepen, but couldn’t make it work: here’s the link. This is the 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>

And this is the CSS.

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

As you can see, when you scrolldown in Codepen the nav items don’t change, but in Codeply they do.

Does anyone know what’s wrong?

Thanks in advance for your help.

Juan Betancourt.

PS: I think it’s possible that the problem is in the CSS and JavaScript Pen settings or in the body tag attributes.

1

There are 1 answers

0
Carol Skelly On BEST ANSWER

Bootstrap 4 requires Popper.js..

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

Codeply automatically includes it when you select "Bootstrap 4", but codepen does not.