I'm trying to get smooth scrolling between elements to work properly, but if the hash links are enabled then it starts to jump on top and ignore offset. I can't figure out how to fix it. Maybe someone can help?
$('a[href^="#"]')
    .not('[href$="#"]')
    .not('[href$="#0"]')
    .on("click", function() {
    var $offset = $("#nav").height();
    var target = this.hash;
    $("html, body").stop().animate({
    scrollTop: $(target).offset().top - $offset
  }, 1000, function() {
    window.location.hash = target; // Enable hash links
  });
    return false;
});
Demo: https://jsfiddle.net/Lugjqk24/
Thank you.
 
    