Archived topic
Scroll Behavior not working
9 replies · Started by Elia on June 29, 2020
Hi there,
We are using the gutenberg anchor links. And we want to make them smooth. What is the best way for that?
We enable smooth scroll on the options:
https://docs.generatepress.com/article/smooth-scroll/
But it doesn't work out of the box
Many thanks
Hi there,
smooth scroll works when the link element has the smooth-scroll class - see here for reference:
https://docs.generatepress.com/article/smooth-scroll/#regular-links
But you can add the PHP Snippet provided here so it applies to any <a> element:
https://docs.generatepress.com/article/generate_smooth_scroll_elements/
Thanks a lot, David! Top class as usual
glad to be of help
Hi!
And sorry for adding another comment here, but I actually happen to have the same problem:
I have added the "smooth-scroll" class in some anchor links that I already had, example:
<a href="#Indice">Volver al Índice</a>
Editing the message after checking that the html of the anchor text is tranform into the anchor text itself: As I read in https://docs.generatepress.com/article/smooth-scroll/#regular-links I just added " class="smooth-scroll" " in between de "a" and the "href".
But it is not working... The link works, but not the smooth scroll
Also, and I don´t know if I have done it well, I have added the following code in the "functions.php" (I´m using a child theme and I read I could do this).
add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
$elements[] = 'a[href*="#"]';
return $elements;
} );
But it is not working either... I´m using the lazy load functionality that comes with the plugin "smush image", I don´t know if thats related but I have seen you were talking about it in anothe thread in this forum. XD
Thanks in advance for your help!
Juan
Hi there,
Any chance you can link us to your page so we can take a look?
Let me know :)
Hi Tom,
Of course!
The site is https://quever-grecia.info/ and the anchor text I mentioned is repeated a few times in the homepage.
Let me know if I can provide you with more info
Hi there,
is the Smooth Scroll option enabled in Customizer > General?
And can you disable your litespeed cache so we can see whats happening
Hi David!
I´m very sorry, the smooth-scroll option was NOT enabled where you said. I didn´t even know it existed there and it looks like I missed the most basic point... Thanks a lot for your help and now it´s working as it should. :)
Regards
Juan
Glad to hear that :)