0

I'm using jQuery smooth scroll code on a wordpress site which I have embedded in the header right above the body </head> tag. My main menu buttons are linking to sections of the same page. When I click these buttons they jump to the section on the same page but the scroll really stutters and is very jittery. However it works smoothly when I use the button "Get your 6.5 Driver Now!" which is not in the main menu (middle left side of the page). Here is the Code:

<script>
  $(function() {
    $('a[href*="#"]:not([href="#"])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          $('html, body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });
    </script>

Is it conflicting with some other code? Does anyone have any ideas? Thanks

Site: http://krankgolf.staging.wpengine.com

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Greg
  • 11
  • 1
  • 6
  • It's conflicting with the native browser behaviour, here's a fiddle https://jsfiddle.net/manoeuvres/cj817q9p/2/ for a similar problem: http://stackoverflow.com/questions/39494904/cant-implement-anchor-smooth-scrolling-with-off-canvas-menu-content/39496602#39496602 I believe there should be a more elegant solution. In addition to your code add `e.preventDefault();` after your `click(function(...` line, and know that `click` function in this manner has been depricated to `on` as in: `$( "p" ).on( "click", function(e) {...` – Sam0 Sep 21 '16 at 23:28
  • @Sam0: where does it say that .click() is deprecated? In the docs it states that .click() is a shortcut for on('click'): http://api.jquery.com/click/ – Omnisite Sep 23 '16 at 22:10
  • @Omnisite you're correct, my mistake, I was thinking of something else. If click was deprecated in that manner a large part of the internet would probably break. – Sam0 Sep 23 '16 at 23:52

0 Answers0