Site logo

Archived topic

EASY SMOOTH SCROLL LINKS

7 replies · Started by Anonymous on June 28, 2016

Viewing posts 1–8 of 8

I have installed easy smooth scroll link add on and it does not seem to be working with generate press theme I have my page set up as sections see http://perfekttension.com/perfekt-tension/

Is there a way to smooth scroll to anchors?

My anchors are on the menu to the section on the page I am not sure if this is issue with the plug in or not

Is there a way to add smooth scroll to the anchor?

Place this in your wp-footer hook


<script>
// smooth scrolling thanks to https://css-tricks.com/snippets/jquery/smooth-scrolling/

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

Thanks I did what you suggested but when I click the link to the anchor it just jumps right to that section of the page?

Try removing the spaces from your IDs and replacing them with dashes.

I found where the error was. The script actually works.
But the "J"'s in jQuery where Uppercase
they must be Lowercase, so the working script corrected is here:


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

you can see a working demo here: http://onepager.artomultiplo.net/

Thanks removing the space worked and the code also worked.

Awesome :)

This archived topic is closed to new replies.