Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1472596

    Hi,
    I read several threads here but found no solution. I want to deep link and jump to a tab section and open a certain tab simultaneously. Is there an actual way to solve this?
    Thanks, Stefan

    #1472628

    Hey westefan,
    This was added a while back and works on my install without any added code. Ensure that you add a custom ID to each tab:
    Screen Shot 2024 11 30 at 12.09.37 PM
    and use a link with the ID “elements/tabs#tabthree” the page will scroll up and open the tab”
    Screen Shot 2024 11 30 at 12.12.41 PM
    If you are using the sticky header and the tab is too close to the header, you can add this code to the end of your child theme functions.php file in Appearance ▸ Editor to adjust the position:

    function custom_script() { ?>
      <script>
    (function($) {
    $(document).ready(function() {
        $('a[href^="#"]').click(function(e) {
            var targetHash = this.hash;
            setTimeout(function() {
                $('html, body').animate({
                    scrollTop: $(targetHash).offset().top - 100
                }, 500);
            }, 100);
        });
        
        if (window.location.hash) {
            $('html, body').animate({
                scrollTop: $(window).scrollTop() - 100
            }, 500);
        }
    });
    }(jQuery));
    </script>
      <?php
    }
    add_action( 'wp_footer', 'custom_script', 99 );

    Screen Shot 2024 11 30 at 12.46.39 PM

    Best regards,
    Mike

    #1472713

    Hey Mike,
    thank you but I didn’t mean a tab element but a tab section. And if I use a link like “/page#tabthree” the tabthree opens but the focus is on top of the page and not the top of the section. Or do I understand something wrong?
    Best regards
    Stefan

    #1472771

    Hi,

    Thank you for the update.

    Please try this script instead:

    function ava_custom_script_tab_section_scroll() {
        ?>
        <script type="text/javascript">
            (function($) {
                function avGetHashFromEvent(event, target) {
                    if (event === 'load') {
                        return window.location.hash;
                    }
                    var locationHash = $(target).attr('href');
                    return locationHash ? locationHash.substring(locationHash.indexOf('#')) : '';
                }
    
                function avScrollToTab(hash) {
                    if (!hash) return;
    
                    var tab = $('.av-section-tab-title[href="' + hash + '"]');
                    var parentContainer = tab.closest('.av-tab-section-outer-container');
    
                    if (tab.length && parentContainer.length) {
                        var position = parentContainer.offset().top;
    
                        tab.trigger('click');
    
                        setTimeout(function() {
                            $('html, body').animate({ scrollTop: position - 100 }, 500);
                        }, 300);
                    }
                }
    
                function avTriggerScrollToTab(selector, event) {
                    $(selector).on(event, function(e) {
                        var hash = avGetHashFromEvent(event, this);
                        avScrollToTab(hash);
                    });
                }
    
                $(document).ready(function() {
                    var tabs = $('.av-tab-section-container');
                    if (tabs.length === 0) return;
    
                    avTriggerScrollToTab('.menu-item a', 'click');
    
                    $(window).on('load', function() {
                        avScrollToTab(window.location.hash);
                    });
                });
            })(jQuery);
        </script>
        <?php
    }
    add_action('wp_footer', 'ava_custom_script_tab_section_scroll', 9999);
    
    

    Best regards,
    Ismael

    #1472780

    Hi Ismael,
    thanks! As before: the tab opens but there is no scrolling to the section. To look try:
    https://chiway.ch/chiway-fuer-alumni/#stelleninserate
    Best regards
    Stefan

    #1472868

    Hi!

    Thank you for the update.

    We adjusted the script a bit — please try it again. If it’s still not working, please provide the login details in the private field so that we can test it.

    function ava_custom_script_tab_section_scroll() {
        ?>
        <script type="text/javascript">
            (function($) {
                function avScrollToTab(hash) {
                    if (!hash) return;
    
                    var anchorElement = $('[href="' + hash + '"]');
                    var parentTab = anchorElement.closest('.av-layout-tab');
                    var tabSectionId = parentTab.data('tab-section-id');
    
                    if (tabSectionId) {
                        var targetTab = $('.av-section-tab-title[href="#' + tabSectionId + '"]');
                        if (targetTab.length) {
                            var position = targetTab.offset().top;
    
                            targetTab.trigger('click');
    
                            setTimeout(function() {
                                $('html, body').animate({ scrollTop: position - 100 }, 500);
                            }, 300);
                        }
                    }
                }
    
                $(document).ready(function() {
                    $(window).on('load', function() {
                        avScrollToTab(window.location.hash);
                    });
                });
            })(jQuery);
        </script>
        <?php
    }
    add_action('wp_footer', 'ava_custom_script_tab_section_scroll', 9999);
    
    

    Best regards,
    Ismael

    #1472913

    Hi Ismael,
    now it works – many thanks!
    Best regards
    Stefan

    #1472936

    Hi,
    Glad Ismael could help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Deep link and open tab’ is closed to new replies.