Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1352002
    krealiners
    Participant

    Hi, I would like to open accordion elements not only clicking on it, but also using a menu link.

    In this page http://www.lifefranca.eu/it/progetto/ you can see an accordion and in correspondance of menu voice PROGETTO the sub-voice linked with every accordion element. At thi moment they are a simple anchor to accordion elements.

    How can I achieve to open directly accordion elements when clickin on PROGETTO sub menu?

    Thanks in advance

    #1352235
    Joao
    Moderator

    Hi There,

    Please follow this thread:

    https://community.theme.co/forums/topic/accordion-external-link/

    Let us know how it goes,

    Thanks

    #1353365
    krealiners
    Participant

    Hi, I’ve read this thread and I try to apply the customizations to my website.

    I’ve put inside Appearance > Customizer > Custom > Javascript the two following piece of code:

    jQuery ( function ( $ ) {

    var hash = window.location.href.split(‘#’)[1];

    if ( hash !== undefined && $(‘.page-id-72 a[href^=”#collapse”]’).length > 0 ) {

    $(document).ready ( function() {

    $( ‘a[href^=”#’ + hash + ‘”]’ ).trigger(‘click’);

    } );

    }

    } );

    and then

    (function($){
    var pageAddress = window.location.hash;

    if ( pageAddress || pageAddress != ” ) {

    console.log(pageAddress);

    var navbar = $(‘.x-navbar’).outerHeight();
    var yloc = $(pageAddress).offset().top – 160;
    console.log($(pageAddress).offset().top);
    console.log(‘tab: ‘ + pageAddress + ‘, yloc: ‘ + yloc);

    $(‘.x-accordion-toggle[href^=”‘ + pageAddress + ‘”‘).trigger(‘click’);

    $(‘html, body’).animate({
    scrollTop: yloc
    }, 850, ‘easeInOutExpo’);
    }

    })(jQuery);

    But the accordion sections doesn’t open.

    Can you check and tell if I’m wrong in some passage.

    Thank you so much

    #1353450
    Lely
    Moderator

    Hi There,

    Please try using the following code instead:

    jQuery( function( $ ) {
      $( document ).ready ( function() {
        if(window.location.hash){
           var target_tab = window.location.hash; 
           if(target_tab!=''){
               $( target_tab +' .x-accordion-heading>a').click();
           }
        }		
        $('.open-accordion-btn a').click(function(){ 
               var target_tab =  $(this).attr('href').split("#").slice(-1)[0];
               $( '#'+target_tab  +' .x-accordion-heading>a').click();
    	});
        
    	 
     });
    });

    Then on Appearance > menu > Submenu Link > Add open-accordion-btn on the CSS classes button. See attached screen shot.

    Hope this helps.

    #1353591
    krealiners
    Participant

    Thanks very much, now it’s working!

    #1353634
    Lely
    Moderator

    You’re welcome!

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1352002 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>