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

    Hi there,

    please have a look at the website in private content. The links on the calendar pagination (page number or next/previous button) are causing an auto scroll to top. So the user has to scroll down to get to the events again. Is there any chance to prevent that auto scroll.

    I already had the people at the Events Calendar support have a look at the issue, but the issue seems unlikely to be coming from them.

    Thanks in advance!

    Best regards
    Marco

    #1455356

    Hey Marco,
    Thank you for your patience and the link to your page, when the tribe event pagination is clicked the page reloads with the new content, this is why the page shows at the top like any new page would when you use a link to a different page.
    To get the scroll position when the pagination button is clicked and then after the page reloads go back to that position add this code to the end of your child theme functions.php file in Appearance ▸ Editor:

    function adjust_scroll_position_when_tribe_events_pagination_is_used() { ?>
      <script>
    document.addEventListener('DOMContentLoaded', function () {
        function storeScrollPosition() {
            localStorage.setItem('scrollPosition', window.scrollY);
        }
        function scrollToStoredPosition() {
            const scrollPosition = localStorage.getItem('scrollPosition');
            if (scrollPosition) {
                window.scrollTo({
                    top: parseInt(scrollPosition, 10),
                    behavior: 'smooth'
                });
                localStorage.removeItem('scrollPosition'); 
            }
        }
        const paginationLinks = document.querySelectorAll('.pagination-tribe_events a');
        paginationLinks.forEach(link => {
            link.addEventListener('click', storeScrollPosition);
        });
        scrollToStoredPosition();
    });
    </script>
      <?php
    }
    add_action( 'wp_footer', 'adjust_scroll_position_when_tribe_events_pagination_is_used', 99 );

    Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.

    Best regards,
    Mike

    #1458016

    Hi Mike,

    thanks a lot! Works like a charm. Awesome support as always!

    Feel free to close the topic.

    Greets
    Marco

    #1458306

    Hi,

    Great, I’m glad that Mike could help you out. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘The Events Calendar Pro – prevent auto scroll to top’ is closed to new replies.