Bootstrap Scrollspy & Smooth-Scroll
<p>I am having some trouble with scrollspy and smooth scrolling. Please keep in mind that I am new to this thing, just good with my google-fu. :)</p>

<p>The problem is quite frustrating, I 've been trying a whole lot of different solutions the past couple of days but none seems to be working. I am using bootstrap scrollspy and smooth scrolling on single page with 4 sections. Each section has its own glyphicon in the navbar, which should turn pink when that section has been scrolled to. When I click the second icon, it works as intended. When I click on the 3rd one, the 2nd one stays pink, that is active. When I click on the 4th one, the 3rd turns white and the 2nd one stays pink. Furthermore, when scrolling manually, only the first two icons change colour. It is probably easier if you see this behaviour yourselves.</p>

<p><a href="http://codepen.io/bohemian83/pen/wMbRZK" rel="nofollow">http://codepen.io/bohemian83/pen/wMbRZK</a></p>

<p>This is my code.</p>

<pre><code>&lt;html&gt;
&lt;body data-spy="scroll" data-offset="50" data-target=".navbar"&gt;

&lt;link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;

&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;

$(document).ready(function() {
    // navigation click actions 
    $('.scroll-link').on('click', function(event){
        event.preventDefault();
        var sectionID = $(this).attr("data-id");
        scrollToID('#' + sectionID, 750);
    });
    // scroll to top action
    $('.scroll-top').on('click', function(event) {
        event.preventDefault();
        $('html, body').animate({scrollTop:0}, 'slow');         
    });
    // mobile nav toggle
    $('#nav-toggle').on('click', function (event) {
        event.preventDefault();
        $('#main-nav').toggleClass("open");
    });
});
// scroll function
function scrollToID(id, speed){
    var offSet = 0;
    var targetOffset = $(id).offset().top - offSet;
    var mainNav = $('#main-nav');
    $('html,body').animate({scrollTop:targetOffset}, speed);
    if (mainNav.hasClass("open")) {
        mainNav.css("height", "1px").removeClass("in").addClass("collapse");
        mainNav.removeClass("open");
    }
}

if (typeof console === "undefined") {
    console = {
        log: function() { }
    };
}

&lt;/script&gt;


&lt;style&gt;

@import url(https://fonts.googleapis.com/css?family=Poiret+One);

.google {
  font-family:"Poiret One",sans-serif;
}

.navbar .navbar-brand {
    color: white !important;
}

.navbar .navbar-nav &gt; li &gt; a {
   color: white;
   padding: 20px 30px 10px 30px;
}

.navbar {
   background-color: transparent;
   background: transparent;
   border-color: transparent;
   padding-top: 30px;
   color: white;
}

.navbar .nav &gt; li.current-menu-item &gt; a, .navbar .nav &gt; li.current-menu-ancestor &gt; a, 
.navbar .nav &gt; li &gt; a:hover, .navbar .nav &gt; li &gt; a:focus {
   background-color: rgba(255,255,255,0);
   color: pink;
}

ul.nav li.active a {
    color: pink;
}

.glyphicon {
    font-size: 20px;
}

.navbar-toggle .icon-bar {
    display: block;
    width: 22px;
    height: 2px;
    border-radius: 1px;
    background-color: white /* change this to any color you want! */;
}

#first {
  background: url(http://i1055.photobucket.com/albums/s503/pgrigorakis/wallpaper-1948122_zpsjnr4n9n2.jpg) no-repeat bottom left;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;

}

#second {
  background: url(http://i1055.photobucket.com/albums/s503/pgrigorakis/meteora-10_zps7j9jqszn.jpg) no-repeat bottom left;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

#third {
  background: url(http://i1055.photobucket.com/albums/s503/pgrigorakis/duesseldorf_wertig_zps1hk1ollh.jpg) no-repeat bottom left;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}


#fourth{
  background: url(https://i.ytimg.com/vi/24i8G5a5d5Q/maxresdefault.jpg) no-repeat bottom left;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: 100% 100%;
  width: 100%; 
  height: 90%;
  min-height:90%;
}

html, body, #first, #second, #third, #fourth {
    height: 100%;
}

#myName {

    font-weight: bold;
    font-size: 50px;
}

@media (max-width: 768px){
  .navbar-nav li{
    text-align: right;
  }
}

html, #first, #second, #third, #fourth {
    height: 100%;
}

body {
  position: relative;
}

#myName {

    font-weight: bold;
    font-size: 50px;
}

@media (max-width: 768px){
  .navbar-nav li{
    text-align: right;
  }
}

&lt;/style&gt;



  &lt;nav role="navigation" class="navbar navbar-fixed-top"&gt;

    &lt;div class="container-fluid"&gt;
      &lt;div class="navbar-header"&gt;
        &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;
        &lt;span class="icon-bar"&gt;&lt;/span&gt;   
      &lt;/button&gt;
        &lt;a class="navbar-brand google" href="#" style="margin-left:80px" id="myName"&gt;PANAGIOTIS&lt;/a&gt;
      &lt;/div&gt;
      &lt;div class="navbar-collapse collapse pull-right" style="margin-right:50px"&gt;
        &lt;ul class="nav navbar-nav"&gt;
          &lt;li&gt;&lt;a class="scroll-link" data-id="first" href="#first"&gt;&lt;span class="glyphicon glyphicon-home" id="ul-selected"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a class="scroll-link" data-id="second" href="#second"&gt;&lt;span class="glyphicon glyphicon-user" id="ul-selected"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a class="scroll-link" data-id="third" href="third"&gt;&lt;span class="glyphicon glyphicon-th" id="ul-selected"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a class="scroll-link" data-id="fourth" href="fourth"&gt;&lt;span class="glyphicon glyphicon-envelope" id="ul-selected"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;/div&gt;
  &lt;/nav&gt;

  &lt;section id="first"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-12"&gt;
          &lt;h1&gt;&lt;/h1&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;

  &lt;section id="second"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-12"&gt;
          &lt;h1&gt;&lt;/h1&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;

  &lt;section id="third"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-12"&gt;
          &lt;h1&gt;&lt;/h1&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;

  &lt;section id="fourth"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
        &lt;div class="col-md-12"&gt;
          &lt;h1&gt;&lt;/h1&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/section&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>