How to Implement both Horizontal and Vertical Smooth Scrolling
<p>I've been putting together a personal project. I'm relatively new to Java so picking it up as I go along.</p>

<p>Basically I have created a site which has sections I want accessible along both the x and y axis.</p>

<p>I have made these sections accessible using anchor links, so the site does link to these div's.</p>

<p>I have also managed to set up the Vertical smooth scroll animation. So my page can auto scroll up and down seamlessly using the following code:</p>

<pre><code>$(document).ready(function(){
$('a[href^="#"]').on('click',function (e) {
    e.preventDefault();

    var target = this.hash;
    var $target = $(target);

    $('html, body').stop().animate({
        'scrollTop': $target.offset().top
    }, 900, 'swing', function () {
        window.location.hash = target;
     });
    });
  });
</code></pre>

<p>However I can't seem to get the same scroll affect to apply for the div's located left/ right. what I want to happen is if I click a link which should go to a Div located to the left or right (off screen) it does a similar seamless smooth scroll left or right while keeping the same up/down animation.</p>

<p>Basically I want to apply both vertical and Horizontal smooth scrolling on the same page.</p>

<p>What changes or additions do I need to make to apply this?</p>

<hr>

<p>I managed to implament horizontal scrolling on my site by making some tweaks to the above code.</p>

<pre><code>$(document).ready(function(){
  $('a[href^="#"]').on('click',function   (e) {
   e.preventDefault();

var target = this.hash;
var $target = $(target);

$('html, body').stop().animate({
     'scrollLeft': $target.offset().left
}, 900, 'swing', function () {
    window.location.hash = target;
     });
     });
   });
</code></pre>

<p>This seems to work with horizontal scrolling. Now I need to make these work together at the same time...</p>

<p>I've added both to a seperate file and referenced them in my HTML. However now only the horizontal works. Anyway to make both work at the same time?</p>