[Resolved] Customising Smooth Scroll Criteria

Home Forums Support [Resolved] Customising Smooth Scroll Criteria

Home Forums Support Customising Smooth Scroll Criteria

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1627166
    Scott

    Hello,

    I’m using the GP smooth scroll on my site. I edited how it loads, to select only links within my class of “.entrycontent”.

    Using this code:

    /* Add smooth scroll to entry copy anchor links */
    
    add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
      $elements[] = '.entry-content a[href*="#"]';
      
      return $elements;
    } ); 

    It works well and is convenient for the client, as they can just create anchor links and enjoy the smooth scroll without having to worry about adding additional classes to content. But recently, I have added a tabbed accordion module, which uses anchors to reference the tabbed content visible. The new tabbed content doesn’t work well if it scrolls every time someone clicks on a tab.

    So I’m wondering if there is a way to exclude certain css classes in this function as well? E.g. Include anchor links within the CSS class “entry-content” AND exclude links within the CSS class “tabbed-content”.

    This way I could exclude the links in the tabbed content. Thank you!

    #1627328
    David
    Staff
    Customer Support

    Hi there,

    you can do something like this:

    .entry-content > *:not(.tabbed-content) a[href*="#"]

    That should target an anchor that is inside an element that does NOT have the tabbed-content class.
    This does mean it will only target links that are inside another container such as a paragraph or within a button wrapper.

    IF thats not right then share a link to where i can see the tabbed content

    #1627412
    Scott

    Works great, thank you so much!

    #1627494
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.