Site logo

Archived topic

Smooth Scroll one page to another

12 replies · Started by Mr McMarry on November 15, 2018

Viewing posts 1–13 of 13

Hi there,

Looks like the detailed instructions is provided in the post you linked. It shouldn’t be theme specific.

It’s a quite complicated solution so if you are having trouble, might be worth commenting on the post and see if the author can help :)

I mean where to put the code to make it work i put it function.php then child theme script.js then element hooks and legacy hook too

Javascript can go in wp_footer hook in Hooks Elements.

Copied and pasted the code in wp-footer with <script type="text/javascript"></script>

<script type="text/javascript">
var jump=function(e)
{
       //prevent the "normal" behaviour which would be a "hard" jump
       e.preventDefault();
   //Get the target
   var target = $(this).attr("href");
   //perform animated scrolling
   $('html,body').animate(
   {
           //get top-position of target-element and set it as scroll target
           scrollTop: $(target).offset().top
   //scrolldelay: 2 seconds
   },2000,function()
   {
           //attach the hash (#jumptarget) to the pageurl
           location.hash = target;
   });

}

$(document).ready(function()
{
       $('a[href*=#]').bind("click", jump);
       return false;
});</script>

Do i have to use some class in the button or something i am missing ?

What buttons? I'm not quite sure how that solution works.

Looks quite complicated. Might be worth commenting on the actual post and see if the author of the code can help.

Tom refer the post so i thought it will be direct solution it will take a time.

That code looks like it would work, but you'll need to replace $ characters with jQuery so it works in WordPress.

Not Working

<script type="text/javascript">
var jump=function(e)
{
       //prevent the "normal" behaviour which would be a "hard" jump
       e.preventDefault();
   //Get the target
   var target = jQuery(this).attr("href");
   //perform animated scrolling
   jQuery('html,body').animate(
   {
           //get top-position of target-element and set it as scroll target
           scrollTop: jQuery(target).offset().top
   //scrolldelay: 2 seconds
   },2000,function()
   {
           //attach the hash (#download) to the pageurl
           location.hash = target;
   });

}

jQuery(document).ready(function()
{
       jQuery('a[href*=#]').bind("click", jump);
       return false;
});</script>

changed with jQuery

You may need to continue searching for a working solution if that one doesn't work for you.

This one might be helpful: https://stackoverflow.com/a/45366628/2391422

You'll just need to remember to change $ to jQuery or else it won't work in WordPress.

Nothings Working help please

You might need to hire a developer to code a custom solution for you then.

We try to help as much as possible but this is really out of the scope of this support forum as it isn't related to GeneratePress.

Thanks for your understanding.

:)

This archived topic is closed to new replies.