Site logo

Archived topic

Smooth Scroll - Stop scrolling to top of page when the side menu is opened.

3 replies · Started by Scott on May 14, 2020

Viewing posts 1–4 of 4

Hello,

I use GP's sticky, slide out menu.

I recently enabled smooth scroll. And targeted it on my anchor links using the code in your documentation:

add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
  $elements[] = 'a[href*="#"]';
  
  return $elements;
} );

The scroll works great on the anchor links!

But, now every time I open the slideout menu it scrolls me to the top of the page. I'd rather just the default behaviour applied, so opening the slide out menu does not bring you back to the top of the page.

Is there a fix?

Thank you!

Hi there,

depending on where the smooth-scroll links are you can be more specific e.g this only affects links inside the entry content:

add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
  $elements[] = '.entry-content a[href*="#"]';
  
  return $elements;
} ); 

Let us know.

Amazing thank you!

You're welcome

This archived topic is closed to new replies.