title: anchor not scrolling to the very top
body: <p>When you click on <em>home</em> you don't get scrolled to the very top. There is still a bit that you have to scroll manually. How can I set home to the top?</p>
  <p>Could be using <code>position: sticky</code> instead of <code>position: fixed</code> a better option?</p>
  <p>If so how do I correctly replace the state of my navbar?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// header Effekt beim scrollen
  
  $(function() {
    var shrinkHeader = 100;
    $(window).scroll(function() {
      var scroll = getCurrentScroll();
      if (scroll &gt;= shrinkHeader) {
        $('#navbar').addClass('shrink');
      } else {
        $('#navbar').removeClass('shrink');
      }
    });
  
    function getCurrentScroll() {
      return window.pageYOffset || document.documentElement.scrollTop;
    }
  });
  // JavaScript Document
  
  $(document).ready(function() {
  
    var navTop = $('#navbar').offset().top;
    var navHeight = $('#navbar').height();
    var windowH = $(window).height();
  
    $('.section').height(windowH);
  
    $(document).scroll(function() {
      var st = $(this).scrollTop();
  
      //for the nav bar:
      if (st &gt; navTop) {
        $('#navbar').addClass('fix');
        $('.section:eq(0)').css({
          'margin-top': navHeight
        }); //fix  scrolling issue due to the fix nav bar
      } else {
        $('#navbar').removeClass('fix');
        $('.section:eq(0)').css({
          'margin-top': '0'
        });
      }
  
      $('.section').each(function(index, element) {
        if (st + navHeight &gt; $(this).offset().top &amp;&amp; st + navHeight &lt;= $(this).offset().top + $(this).height()) {
          $(this).addClass('active');
  
          var id = $(this).attr('id');
          $('a[href="#' + id + '"]').parent('li').addClass('active');
          // or $('#nav li:eq('+index+')').addClass('active');
        } else {
          $(this).removeClass('active');
  
          var id = $(this).attr('id');
          $('a[href="#' + id + '"]').parent('li').removeClass('active');
          //or $('#nav li:eq('+index+')').removeClass('active');
        }
  
      });
  
    });
  
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>@charset "utf-8";
  
  /* CSS Document */
  
  * {
    font-family: 'Roboto', sans-serif;
  }
  
  #container {
    width: 1280px;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
  }
  
  body {
    background-color: white;
    margin: 128px 0 0 0;
  }
  
  
  /* Navigation */
  
  #navlinks {
    margin: 0;
  }
  
  ul {
    color: black;
    list-style: none;
    float: right;
    margin-right: 20px;
    padding-top: 30px;
  }
  
  ul li {
    display: inline-table;
    margin-left: 5px;
    padding: 5px;
    border-bottom: 1.5px solid;
    border-bottom-color: white;
  }
  
  ul li a {
    color: black;
    text-decoration: none;
    padding: 10px;
  }
  
  
  /* Smart Navbar / weiß, wo man auf der Seite ist von https://stackoverflow.com/questions/19697696/change-underline-of-active-nav-by-section */
  
  #navbar.fix {
    position: fixed;
    top: 0;
  }
  
  #navbar li.active {
    border-bottom: 1.5px solid;
    border-bottom-color: #f6bd60;
  }
  
  
  /* Smart Navbar Ende */
  
  
  /* fixed Navigation von https://codepen.io/malZiiirA/pen/cbfED?css-preprocessor=none */
  
  #navbar {
    border-bottom-style: solid;
    border-bottom-width: 1.25px;
    box-shadow: 0px 2.5px 5px rgba(0, 0, 0, 0.2);
    background-color: white;
    height: 128px;
    transition: 0.32s;
    position: fixed;
    top: 0;
    width: 1280px;
  }
  
  #navbar.shrink {
    height: 80px;
    line-height: 18px;
  }
  
  #navbar li {
    font-size: 1.2rem;
    font-weight: normal;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
  }
  
  #navbar.shrink li {
    font-size: 1.2rem;
    margin-top: -30px;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
  }
  
  #navbar img {
    height: 128px;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
  }
  
  #navbar.shrink img {
    height: 80px;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
    margin: auto;
  }
  
  
  /* fixed nav Ende */
  
  
  /*
  #spacer {
    height: 128px;
    border-bottom: 4px solid;
  }
  
  
    margin-top: 0 !important;
  */
  
  #home {
    height: 100% !important;
    display: block;
    padding-top: 80px;
    z-index: -1;
    position: relative;
    top: -80px;
  }
  
  #wir-ueber-uns {
    height: 50px;
    display: block;
    margin-top: -80px;
    padding-top: 80px;
    z-index: -2;
    background-color: lightblue;
    position: relative;
    top: -80px;
  }
  
  #aktionen {
    height: 100%;
    display: block;
    margin-top: -80px;
    padding-top: 80px;
    z-index: -3;
    background-color: blue;
    position: relative;
    top: -80px;
  }
  
  #terminvereinbarung {
    height: 100%;
    display: block;
    margin-top: -80px;
    padding-top: 80px;
    z-index: -4;
    background-color: red;
    position: relative;
    top: -80px;
  }
  
  #infos {
    height: 100%;
    display: block;
    margin-top: -80px;
    padding-top: 80px;
    z-index: -5;
    background-color: yellow;
    position: relative;
    top: -80px;
  }
  
  #logo {
    margin-left: 50px;
  }
  
  #homebild {
    width: 100%;
    height: 100%;
  }
  
  footer {
    background-color: lightblue;
    display: grid;
    grid-template-columns: 426px 426px 450px;
    grid-template-rows: 500px;
    gap: 0px 0px;
    grid-template-areas: ". .";
  }
  
  #impressum {
    line-height: 1.5rem;
    font-size: 1rem;
    padding-left: 30px;
    padding-top: 4rem;
    height: 500px;
  }
  
  h3 {
    font-size: 1.2rem;
  }
  
  h4 {
    font-size: 1.2rem;
    text-transform: uppercase;
  }
  
  #datenschutz {
    background-color: lightgreen;
    line-height: 1.5rem;
    font-size: 1rem;
    padding-left: 30px;
    padding-top: 4rem;
  }
  
  
  /* Hover Effekt bei Navigation von https://github.com/IanLunn/Hover/blob/master/css/hover.css */
  
  .hvr-sweep-to-top {
    display: inline-block;
    vertical-align: middle;
    -webkit-transform: perspective(1px) translateZ(0);
    transform: perspective(1px) translateZ(0);
    box-shadow: 0 0 1px rgba(0, 0, 0, 0);
    position: relative;
    -webkit-transition-property: color;
    transition-property: color;
    -webkit-transition-duration: 0.3s;
    transition-duration: 0.3s;
  }
  
  .hvr-sweep-to-top:before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f6bd60;
    -webkit-transform: scaleY(0);
    transform: scaleY(0);
    -webkit-transform-origin: 50% 100%;
    transform-origin: 50% 100%;
    -webkit-transition-property: transform;
    transition-property: transform;
    -webkit-transition-duration: 0.3s;
    transition-duration: 0.3s;
    -webkit-transition-timing-function: ease-out;
    transition-timing-function: ease-out;
  }
  
  .hvr-sweep-to-top:hover,
  .hvr-sweep-to-top:focus,
  .hvr-sweep-to-top:active {
    color: white;
  }
  
  .hvr-sweep-to-top:hover:before,
  .hvr-sweep-to-top:focus:before,
  .hvr-sweep-to-top:active:before {
    -webkit-transform: scaleY(1);
    transform: scaleY(1);
  }
  
  
  /* Hover Effekt Ende */
  
  
  /* Loader */
  
  .loader {
    display: inline-block;
    width: 30px;
    height: 30px;
    position: relative;
    border: 4px solid #Fff;
    animation: loader 2s infinite ease;
  }
  
  .loader-inner {
    vertical-align: top;
    display: inline-block;
    width: 100%;
    background-color: #fff;
    animation: loader-inner 2s infinite ease-in;
  }
  
  @keyframes loader {
    0% {
      transform: rotate(0deg);
    }
    25% {
      transform: rotate(180deg);
    }
    50% {
      transform: rotate(180deg);
    }
    75% {
      transform: rotate(360deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
  
  @keyframes loader-inner {
    0% {
      height: 0%;
    }
    25% {
      height: 0%;
    }
    50% {
      height: 100%;
    }
    75% {
      height: 100%;
    }
    100% {
      height: 0%;
    }
  }
  
  .loader-wrapper {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background-color: #242f3f;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  
  /* loader Ende */</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
    &lt;title&gt;OptikTack&lt;/title&gt;
    &lt;link href="style.css" rel="stylesheet" type="text/css"&gt;
    &lt;link href="https://fonts.googleapis.com/css2?family=Roboto&amp;display=swap" rel="stylesheet"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;div id="container"&gt;
      &lt;div class="body"&gt;
        &lt;!-- Navigation --&gt;
        &lt;nav id="navbar"&gt;
          &lt;script class="cssdeck" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.0/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script src="javascript/navbar fixed.js"&gt;&lt;/script&gt;
          &lt;a href="#home" id="logo"&gt;&lt;img src="https://i.postimg.cc/przxCGcx/Logo.png"&gt;&lt;/a&gt;
          &lt;ul&gt;
            &lt;li class="hvr-sweep-to-top active"&gt;&lt;a href="#home"&gt;Home&lt;/a&gt;&lt;/li&gt;
            &lt;li class="hvr-sweep-to-top"&gt;&lt;a href="#wir-ueber-uns"&gt;Wir über uns&lt;/a&gt;&lt;/li&gt;
            &lt;li class="hvr-sweep-to-top"&gt;&lt;a href="#aktionen"&gt;Aktionen&lt;/a&gt;&lt;/li&gt;
            &lt;li class="hvr-sweep-to-top"&gt;&lt;a href="#terminvereinbarung"&gt;Terminvereinbarung&lt;/a&gt;&lt;/li&gt;
            &lt;li class="hvr-sweep-to-top"&gt;&lt;a href="#infos"&gt;Infos&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
        &lt;/nav&gt;
        &lt;!-- body --&gt;
        &lt;div id="spacer"&gt;&lt;/div&gt;
        &lt;!-- home section --&gt;
        &lt;section id="home" class="section"&gt;
          &lt;div&gt;
            &lt;img src="https://i.postimg.cc/tgk5cWmx/Bild-1.jpg" alt="Frau" id="homebild"&gt;
          &lt;/div&gt;
        &lt;/section&gt;
        &lt;!-- UberUns section --&gt;
        &lt;section id="wir-ueber-uns" class="section"&gt;
          &lt;div&gt;
            &lt;p&gt;section 2&lt;/p&gt;
          &lt;/div&gt;
        &lt;/section&gt;
        &lt;!-- Aktionen section --&gt;
        &lt;div id="reference"&gt;&lt;/div&gt;
        &lt;section id="aktionen" class="section"&gt;
          &lt;div&gt;
            &lt;p&gt;section 3&lt;/p&gt;
          &lt;/div&gt;
        &lt;/section&gt;
        &lt;!-- Terminvereinbarung section --&gt;
        &lt;section id="terminvereinbarung" class="section"&gt;
          &lt;div&gt;
            &lt;p&gt;section 4&lt;/p&gt;
          &lt;/div&gt;
        &lt;/section&gt;
        &lt;!-- Infos section --&gt;
        &lt;section id="infos" class="section"&gt;
          &lt;div&gt;
            &lt;p&gt;section 5&lt;/p&gt;
          &lt;/div&gt;
        &lt;/section&gt;
  
        &lt;footer&gt;
          &lt;div id="impressum"&gt;
            &lt;h3&gt;Impressum&lt;/h3&gt;
  
            &lt;h4&gt;
              Optik Tack GmbH
            &lt;/h4&gt;
            &lt;p&gt;
              &lt;!-- Icons von https://tablericons.com/ --&gt;
              &lt;!-- map Icon --&gt;
              &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-map-pin" width="16" height="16" viewBox="0 0 24 24" stroke-width="2" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;circle cx="12" cy="11" r="3" /&gt;
                  &lt;path d="M17.657 16.657l-4.243 4.243a2 2 0 0 1 -2.827 0l-4.244 -4.243a8 8 0 1 1 11.314 0z" /&gt;
                &lt;/svg&gt; Mozartstraße 37 &lt;br&gt; 73430 Aalen &lt;br&gt;
              &lt;!-- phone Icon --&gt;
              &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-phone" width="16" height="16" viewBox="0 0 24 24" stroke-width="2" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;path d="M5 4h4l2 5l-2.5 1.5a11 11 0 0 0 5 5l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a16 16 0 0 1 -15 -15a2 2 0 0 1 2 -2" /&gt;
                &lt;/svg&gt; Tel.: 07361/123451 &lt;br&gt;
              &lt;!-- at Icon --&gt;
              &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-at" width="16" height="16" viewBox="0 0 24 24" stroke-width="2" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;circle cx="12" cy="12" r="4" /&gt;
                  &lt;path d="M16 12v1.5a2.5 2.5 0 0 0 5 0v-1.5a9 9 0 1 0 -5.5 8.28" /&gt;
                &lt;/svg&gt; info@optik-tack.de &lt;br&gt;
              &lt;!-- bookmark Icon --&gt;
              &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-bookmarks" width="16" height="16" viewBox="0 0 24 24" stroke-width="2" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;path d="M13 7a2 2 0 0 1 2 2v12l-5 -3l-5 3v-12a2 2 0 0 1 2 -2h6z" /&gt;
                  &lt;path d="M9.265 4a2 2 0 0 1 1.735 -1h6a2 2 0 0 1 2 2v12l-1 -.6" /&gt;
                &lt;/svg&gt; www.optik-tack.de
            &lt;/p&gt;
  
            &lt;p&gt;
              Geschäftsführer: Anton Tack &lt;br&gt; Amtsgericht Aalen &lt;br&gt; Handelsregister Nr. XXX000XXX, &lt;br&gt; Finanzamt Aalen &lt;br&gt; USt.IdNr.: DE10111011 &lt;br&gt;
            &lt;/p&gt;
          &lt;/div&gt;
          &lt;div id="datenschutz"&gt;
            &lt;h3&gt;Datenschutz&lt;/h3&gt;
            &lt;h4&gt;Datenschutzhinweise&lt;/h4&gt;
            &lt;p&gt;gemäß EU-Datenschutz-Grundverordnung (DSGVO)&lt;/p&gt;
          &lt;/div&gt;
          &lt;div id="socialmedia"&gt;
            &lt;!-- Instagram Icon --&gt;
            &lt;a href="#"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-instagram" width="100" height="100" viewBox="0 0 24 24" stroke-width="1.5" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;rect x="4" y="4" width="16" height="16" rx="4" /&gt;
                  &lt;circle cx="12" cy="12" r="3" /&gt;
                  &lt;line x1="16.5" y1="7.5" x2="16.5" y2="7.501" /&gt;
                &lt;/svg&gt;&lt;/a&gt; &lt;br&gt;
            &lt;!-- Facebook Icon --&gt;
            &lt;a href="#"&gt; &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-facebook" width="100" height="100" viewBox="0 0 24 24" stroke-width="1.5" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;path d="M7 10v4h3v7h4v-7h3l1 -4h-4v-2a1 1 0 0 1 1 -1h3v-4h-3a5 5 0 0 0 -5 5v2h-3" /&gt;
                &lt;/svg&gt; &lt;/a&gt;&lt;br&gt;
            &lt;!-- Pinterest Icon --&gt;
            &lt;a href="#"&gt; &lt;svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-pinterest" width="100" height="100" viewBox="0 0 24 24" stroke-width="1.5" stroke="#607D8B" fill="none" stroke-linecap="round" stroke-linejoin="round"&gt;
                  &lt;path stroke="none" d="M0 0h24v24H0z" fill="none" /&gt;
                  &lt;line x1="8" y1="20" x2="12" y2="11" /&gt;
                  &lt;path d="M10.7 14c.437 1.263 1.43 2 2.55 2c2.071 0 3.75 -1.554 3.75 -4a5 5 0 1 0 -9.7 1.7" /&gt;
                  &lt;circle cx="12" cy="12" r="9" /&gt;
                &lt;/svg&gt;&lt;/a&gt;
            &lt;!-- Icons Ende --&gt;
          &lt;/div&gt;
        &lt;/footer&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;!-- Animation am Anfang vom Laden der Seite --&gt;
    &lt;div class="loader-wrapper"&gt;
      &lt;span class="loader"&gt;&lt;span class="loader-inner"&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;/div&gt;
  
    &lt;script&gt;
      $(window).on("load", function() {
        $(".loader-wrapper").fadeOut("slow");
      });
    &lt;/script&gt;
    &lt;!-- Animation Ende --&gt;
    &lt;!-- Smooth Scroll --&gt;
    &lt;script&gt;
      $('a').click(function() {
        $('html, body').animate({
          scrollTop: $($(this).attr('href')).offset().top
        }, 500);
        return false;
      });
    &lt;/script&gt;
    &lt;!-- Smooth Scroll Ende --&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>