- This topic has 7 replies, 4 voices, and was last updated 9 years, 9 months ago by
Tom.
-
AuthorPosts
-
June 28, 2016 at 9:54 am #205136
Daniel
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?
June 28, 2016 at 12:40 pm #205177Roberto Enrique
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>June 30, 2016 at 9:35 am #205666Daniel
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?
June 30, 2016 at 10:42 am #205671Roberto
You’re right, it is not working as expected.
There are some updates to the script, you can find them here:http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
June 30, 2016 at 11:58 pm #205781Tom
Lead DeveloperLead DeveloperTry removing the spaces from your IDs and replacing them with dashes.
July 1, 2016 at 11:31 pm #205913Roberto Enrique
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/
July 2, 2016 at 12:43 am #205927Daniel
Thanks removing the space worked and the code also worked.
July 2, 2016 at 10:33 am #206036Tom
Lead DeveloperLead DeveloperAwesome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.