Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Bootstrap 4 Basics (Retired) Using Bootstrap Components Using ScrollSpy to Highlight Nav Links

Justin Sze Wei Teo
Justin Sze Wei Teo
9,418 Points

ScrollSpy not highlighting "Schedule" when scrolled down to bottom

Hi guys,

As per my title, ScrollSpy highlights my other 3 list items of the navbar (Home,about,speakers), but doesn't seem to highlight "schedule". I've not been able to determine why this is so! Got my code snippet below, anyone care to advise?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Full Stack Conf</title>
    <!-- bootstrap css -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/css/bootstrap.min.css" integrity="sha384-MIwDKRSSImVFAZCVLtU0LMDdON6KVCrZHyVQQj6e8wIEJkW4tvwqXrbMIya1vriY" crossorigin="anonymous">
  </head>
  <body id="home" data-spy="scroll" data-target=".navbar">
    <!--navbar-->
  <nav class="navbar navbar-dark bg-primary navbar-fixed-top">
    <div class="container">
      <ul class="nav navbar-nav">
        <li class="nav-item">
          <a class="nav-link" href="#home">Home <span class="sr-only">             (current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#about">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#speakers">Speakers</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#schedule">Schedule</a>
        </li>
      </ul>
      <a class="navbar-brand pull-sm-right m-r-0 hidden-xs-down" href="http://www.teamtreehouse.com">Presented by Treehouse</a>
    </div>
  </nav>
    <!--/navbar-->

    <!--Jumbotron-->
    <div class="jumbotron jumbotron-fluid bg-info">
      <div class="container text-sm-center p-t-3">
        <h1 class="display-2">Full Stack Conf</h1>
        <p class="lead">A One-day Conference About All Things JavaScript</p>

        <div class="btn-group m-t-2" role="group" aria-label="Basic example">
          <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#register">Register Now</button>
          <a class="btn btn-secondary btn-lg" href="#speakers">See Speakers</a>
        </div>
      </div>
    </div>
    <!--/Jumbotron-->


    <div class="container p-t-2">
      <!--about-->
      <div id="about" class="row">
        <div class="col-lg-4 push-lg-4">
          <h3 class="m-b-2">About Full Stack Conf</h3>
          <img class="m-b-1 img-fluid img-rounded hidden-xs-down" src="img/pdx.jpg" alt="Portland">
          <p>The beautiful city of Portland, Oregon will be the host city for Full Stack Conf!</p>
          <p>Explore the future of JavaScript with a lineup of industry professionals. Discover new techniques           to advance your career as a web developer.</p>
        </div>
      <div class="col-lg-4 pull-lg-4">
        <h3 class="m-b-2">Expert Speakers</h3>
        <p>Our expert speaker lineup was just announced, so don't wait too long before grabbing your tickets!           </p>
        <p>Want to meet the international JavaScript community and share skills with some of the world's top           experts, hackers, and makers? Be the first to know what to expect for the future of JavaScript.</p>
        <p>Full Stack Conf is committed to being inclusive and welcoming for everyone. We look forward to               another intensive day of learning and sharing.</p>
      </div>
        <div class="col-lg-4">
          <h3 class="m-b-2">What You'll Learn</h3>
          <div class="list-group">

            <a href="#" class="list-group-item"><strong>MongoDB</strong>: NoSQL database</a>
            <a href="#" class="list-group-item"><strong>Angular</strong>: JavaScript framework </a>
            <a href="#" class="list-group-item"><strong>Express</strong>: Framework for Node</a>
            <a href="#" class="list-group-item"><strong>Node.js</strong>: JavaScript environment</a>
            <a href="#" class="list-group-item"><strong>ES2015</strong>: Latest version of JavaScript</a>
            <a href="#" class="list-group-item"><strong>Babel</strong>: JavaScript compiler</a>
          </div>
        </div>
      </div> <!--about-->

      <!--Speakers-->
      <h1 id="speakers" class="display-4 text-xs-center m-  y-3 text-muted">Speakers</h1>
      <div class="row">
        <div class="col-md-6 col-lg-4">
          <div class="card">
            <img class="card-img-top img-fluid" src="img/angie.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">Angie McAngular</h4>
              <p class="card-text">Angie is a web developer and teacher who is passionate about building scalable, data driven web app, especially ones that address old problems with new tech.</p>
            </div>
          </div>
        </div>

        <div class="col-md-6 col-lg-4">
          <div class="card">
            <img class="card-img-top img-fluid" src="img/nodestradamus.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">NodeStradamus</h4>
              <p class="card-text">"NodeStra" is a software engineer and philosopher trying to leave the world better than he found it. He codes for non-profits, eCommerce, and large-scale web apps.</p>
            </div>
          </div>
        </div>

      <div class="col-md-6 col-lg-4">
        <div class="card">
            <img class="card-img-top img-fluid" src="img/geo.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">Geo "Lo" Cation</h4>
              <p class="card-text">Geo is a JavaScript developer working on large-scale applications. He's also a teacher who strives to support students in removing all barriers to learning code.</p>
            </div>
          </div>
         </div>


      <div class="col-md-6 col-lg-4">
        <div class="card">
            <img class="card-img-top img-fluid" src="img/ecma.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">Ecma Scriptnstuff</h4>
              <p class="card-text">Ecma found her passion for computers and programming over 15 years ago. She is excited to introduce people to the wonderful world of JavaScript.</p>
            </div>
          </div>
         </div>


      <div class="col-md-6 col-lg-4">
        <div class="card">
            <img class="card-img-top img-fluid" src="img/jay.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">Jay Query</h4>
              <p class="card-text">Jay is a developer, author of CSS: The Missing Manual, JavaScript &amp; jQuery: The Missing Manual, and web development teacher.</p>
            </div>
          </div>
         </div>

      <div class="col-md-6 col-lg-4">
       <div class="card">
            <img class="card-img-top img-fluid" src="img/json.png" alt="Card image cap">
            <div class="card-block">
              <h4 class="card-title">Json Babel</h4>
              <p class="card-text">All of his professional life, Json has worked with computers online; he is a polyglot programmer and likes using the right tools for the job.</p>
            </div>
          </div>
         </div>



      </div>
      <!-- /speakers -->


      <!--Schedule-->
      <h1 id="schedule" class="display-4 text-xs-center m-y-3 text-muted">Schedule</h1>
      <ul class="list-group">
        <li class="list-group-item">
          <h4 class="list-group-item-heading">Keynote: Internet of Things <span class="tag tag-info tag-pill pull-xs-right">9.00am</span></h4>

          NodeStradamus
        </li>
        <li class="list-group-item">
          <h4 class="list-group-item-heading">Angular Basics<span class="tag  tag-info tag-pill pull-xs-right">10.00am</span></h4>
          Angie McAngular
        </li>
        <li class="list-group-item">
          <h4 class="list-group-item-heading">Hey, Mongo!<span class="tag  tag-info tag-pill pull-xs-right">11.00am</span>             </h4>
          Jay Query
        </li>
        <li class="list-group-item list-group-item-success">
          <h4 class="list-group-item-heading">Lunchbreak<span class="tag  tag-info tag-pill pull-xs-right">12.00pm</span>             </h4>
          Free Pizza for everyone!s
        </li>
      </ul>
      <!--/Schedule-->
      <!--callout button-->

      <button type="button" class="btn btn-outline-info btn-lg d-block m-x-auto m-y-3" data-toggle="modal" data-target="#register">Don't Miss Out, Register Now</button>

      <!-- signup form -->
      <hr>
      <div class="row p-y-2 text-muted">
        <div class="col-md-6 col-xl-5">
          <p><strong>About Treehouse</strong></p>
          <p>Treehouse brings affordable technology education to people everywhere to help them achieve their             dreams and change the world.</p>
        </div>
        <div class="col-md-6 col-xl-5 offset-xl-2">
          <p><strong>Stay up-to-date on Full Stack Conf</strong></p>
          <div class="input-group">
            <input type="text" class="form-control" placeholder="Email">
            <span class="input-group-btn">
              <button class="btn btn-primary" type="button">Sign up</button>
            </span>
          </div>
        </div>
      </div>
      <hr><!-- /signup form -->

      <!--footer-->
      <div class="row p-y-1">
        <div class="col-md-7">
          <ul class="nav nav-inline">
            <li class="nav-item">
              <a class="nav-link active" href="#">Community</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">Tracks</a>
            </li>
            <li class="nav-item">
              <!-- Example split danger button -->
              <div class="btn-group dropup">
                <button type="button" class="btn btn-secondary">Other Confs</button>
                <button type="button" class="btn btn-secondary dropdown-toggle   dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <span class="sr-only">Toggle Dropdown</span>
                </button>
                <div class="dropdown-menu">
                  <a class="dropdown-item" href="#">CSS Conf</a>
                  <a class="dropdown-item" href="#">Python Conf</a>
                  <a class="dropdown-item" href="#">Java Conf</a>               
                  <a class="dropdown-item" href="#">Swift Conf</a>
                </div>
              </div>
            </li>

          </ul>

        </div>
        <div class="col-md-5 text-md-right">
          <small>&copy; 2016 Full Stack Conf &amp; Treehouse</small>
        </div>
      </div>
      <!--footer-->

    </div> <!--container-->

    <!----=========================
    FORM MODAL
  ============================---------->

    <div id="register" class="modal fade">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title">Register for Full Stack Conf</h4>
      </div>
      <div class="modal-body">
        <p>Form goes here...</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->




    <!-- jQuery first, then bootstrap js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js" integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/js/bootstrap.min.js" integrity="sha384-ux8v3A6CPtOTqOzMKiuo3d/DomGaaClxFYdCu2HPMBEkf6x2xiDyJ7gkXU0MWwaD" crossorigin="anonymous"></script>
  </body>
</html>

2 Answers

Justin Sze Wei Teo
Justin Sze Wei Teo
9,418 Points

Oh wait, ignore my last comment.. i realise there' data-offset. That solves all the problems! thanks dude

Steven Parker
Steven Parker
231,275 Points

I pasted this into a codepen and it worked as expected.

I did notice that the trigger point was lower than anticipated because of the header, but all 4 sections did switch highlighting.

Justin Sze Wei Teo
Justin Sze Wei Teo
9,418 Points

Hi Steven,

Thanks for your answer. I had a 2nd look and I think you are right! Very sharp observation you have there. The trigger point is lower than anticipated - i.e. I need to scroll past the "About" section before about is even higlighted. When I tried my code on a larger screen, "Schedule" does get highlighted as I am able to scroll further down to trigger its highlight.

On 2nd examination of the instructor video, I notice Guil's website also has the same problem of a "lower trigger point".

Is there any method to make this trigger point "higher" or more accurate?

Kindly advise, thanks!

Pablo Rocha
Pablo Rocha
10,142 Points

Steven Parker the codepen link you supplied is not valid. Justin figured it out by using the data-offset attribute.

Steven Parker
Steven Parker
231,275 Points

Sorry if my link confused you. It was just a link to codepen itself, I did not actually store anything there (since I did not change the code). I only made it a link in case you were not already familiar with it.