Trying to Use A Smooth Scroller. Script Conflict?

So I’m trying to make my main menu (eventually modifying it’s location) click/scroll smoothly to its destination. But the code I’m using doesn’t seem to be working and I’m wondering if I’m experiencing a jQuery conflict somewhere. I checked my code and do not see any conflicts, so I’m not sure what the hold up is on getting the menu to work.

What is the code that you are using with the intention to achieve the smooth scroll?

The code I’m using is:

 //Use smooth scrolling when clicking on navigation
  $('.navbar 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-topoffset+2
        }, 500);
        return false;
      } //target.length
    } //click function
  }); //smooth scrolling

This is found in my template.js file.

Still haven’t found a solution.

So I’ve decided to try another type of script and still can’t get a smooth scroll to work.

<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>

Using Chrome Developer Tools, I’m not seeing any errors pop up. I’m not sure where to pinpoint the culprit of this not working.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.