<ul id="top-menu">
  <li class="active">
    <a href="#">О нас</a>
  </li>
  <li>
    <a href="#services">Услуги</a>
  </li>
  <li>
    <a href="#reviews">Отзывы</a>
  </li>
  <li>
    <a href="#contacts">Контакты</a>
  </li>
</ul>

<a id="services">Услуги</a>


<a id="reviews">Отзывы</a>


<a id="contacts">Контакты</a>
body {
    height: 6000px;
    font-family: Helvetica, Arial;
}

#top-menu {
    position: fixed;
    z-index: 1;
    background: white;
    left: 0;
    right: 0;
    top: 0;
    list-style: none;
}

#top-menu li {
    float: left;
    background: #eee;
    margin-right: 10px;
}

#top-menu li:last-child {    
    margin-right: 0;
}

#top-menu a {
    display: block;
    padding: 5px 25px 7px 25px;
    width: 4em;
    text-align: center;
    -webkit-transition: .5s all ease-out;
    -moz-transition: .5s all ease-out;
    transition: .5s all ease-out;
    border-top: 3px solid white;
    color: #aaa;
    text-decoration: none;
}

#top-menu a:hover {
    color: #000;
}

#top-menu li.active a {
    border-bottom: 3px solid #333;
    color: #333;
}

#services {
    position: absolute;
    top: 400px;
}

#reviews {
    position: absolute;
    top: 800px;
}

#contacts {
    position: absolute;
    top: 1200px;
}
var lastId,
    topMenu = $("#top-menu"),
    topMenuHeight = topMenu.outerHeight()+15,
    
    menuItems = topMenu.find("a"),
    
    scrollItems = menuItems.map(function(){
      var item = $($(this).attr("href"));
      if (item.length) { return item; }
});

menuItems.click(function(e){
  var href = $(this).attr("href"),
      offsetTop = href === "#" ? 0 : $(href).offset().top-topMenuHeight+1;
  $('html, body').stop().animate({ 
      scrollTop: offsetTop
  }, 300);
  e.preventDefault();
});

$(window).scroll(function(){
   var fromTop = $(this).scrollTop()+topMenuHeight;
   
   var cur = scrollItems.map(function(){
     if ($(this).offset().top < fromTop)
       return this;
   });
   
   cur = cur[cur.length-1];
   var id = cur && cur.length ? cur[0].id : "";
   
   if (lastId !== id) {
       lastId = id;
       
       menuItems
         .parent().removeClass("active")
         .end().filter("[href='#"+id+"']").parent().addClass("active");
   }                   
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js