title: JS Smooth Scroll Vertical & Horizontal Function
body: <p>I want to create a multisite in a one-page, where everytime a link is clicked, it automatically scrolls to that element in the page (all div elements).<br>
  The function works but it still jumps to the given element. </p>
  
  <p>Here's the code I've got so far and the elements I use to call the function:</p>
  
  <pre><code>&lt;li class="topli"&gt;
      &lt;a id="toplink" onclick="Scroll('#home')" href="javascript:void(0);"&gt;HOME&lt;/a&gt;
  &lt;/li&gt;
  
  &lt;script&gt;
      function Scroll(element) {
          var ID = element.split('#').join('');
          var target = document.getElementById(ID);
          var offset = target.getBoundingClientRect();
  
          console.log("X:",offset.x,"Y:",offset.y);
  
          if (window.scrollY != offset.y) {
              window.scroll(window.scrollY, offset.y);
          }
  
          if (window.scrollX != offset.x) {
              window.scroll(window.scrollX, offset.x);
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>If needed I'll add a more detailed code to a JSFiddle.</p>