Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #226417

    Rad
    Moderator

    Hi Christian,

    Your given javascript is incomplete so I really can’t help you with that. But if you’re just referring make menu navbar collapse on clicking menu items, then the updated version should be this.

    jQuery(document).ready(function($) {
      $('.x-nav-wrap.mobile .x-nav a').click(function(){
      $('.x-btn-navbar').click(); 
      });
    });

    Hope this helps.

    #226878

    Christian L
    Participant

    This works great on the browser, but not on mobile. Is there another statement to make it work on iphone?

    Thank you!

    #226886

    Christian L
    Participant

    I tried adding in all the previous fixes, hope this makes the code complete

    jQuery(document).ready(function($) {
    $(‘.x-nav-wrap.mobile .x-nav a’).click(function(){
    $(‘.x-btn-navbar’).click();
    });
    });

    jQuery(function($){

    var window_base = window.location.href.split(“#”).slice(0)[0];
    var window_hash = window.location.href.split(“#”).slice(-1)[0];
    var outbound = /^https?:\/\//i;

    $(‘.x-nav a’).each(function(){ //Scan links and convert them to relative hash for one page navigation’s Active statuses to work properly when manually scrolling

    var hash = $(this).attr(‘href’).split(“#”).slice(-1)[0];
    var anchor_base = $(this).attr(‘href’).split(“#”).slice(0)[0];

    if(hash) { //Does it have hash? then perform check
    if(anchor_base == window_base) { //If same page, then no need to reload, just make it relative
    $(this).attr(‘href’, ‘#’+hash);
    } // Else, leave it that way. So when user clicked, it will just link them to outbound page
    }

    }).click(function(e){ //Enable Parent and Submenu scrolling

    var hash = $(this).attr(‘href’).split(“#”).slice(-1)[0];

    if(hash && !outbound.test( $(this).attr(‘href’) ) ) { //Does it have relative hash?

    e.preventDefault(); //Disable jumping
    e.stopPropagation();

    setTimeout( function(){
    $(‘html,body’).animate({ scrollTop: $(‘#’ + hash ).offset().top – $(‘.x-navbar’).height()},700 ,’swing’);}, 700 );

    //Now add active status for automatic scrolling
    $(‘.x-nav li’).removeClass(‘current-menu-item’);
    $(this).parent().addClass(‘current-menu-item’);

    }

    });

    $(document).ready(function(){ // Enable auto scroll when loaded.

    $(‘.x-nav li’).removeClass(‘current-menu-item’);
    //$(‘a:not([href*=”#”])’).parent().addClass(‘current-menu-item’); For experiment only

    if(window_hash) {
    $(‘a[href$=”#’+window_hash+'”]’).click(); //Click it, so it will use default click from one page navigation event and submenu event
    }
    })

    });

    #226888

    Christian L
    Participant

    Actually, that has made the menu items not line up on a browser, so I’m going back to what you just sent which worked on browser, but not on mobile.

    jQuery(document).ready(function($) {
    $(‘.x-nav-wrap.mobile .x-nav a’).click(function(){
    $(‘.x-btn-navbar’).click();
    });
    });

    Thanks.

    #227271

    Rad
    Moderator

    Hi Christian,

    It’s working on my mobile and iphone. This .x-nav-wrap.mobile targets all mobile menu that being displayed. So I don’t see the reason why it will not work just on iphone.

    Could you try clearing your iphone’s safari cache?

    Thanks!