Hide/show menu when clicking

Asked

Viewed 66 times

2

I’m having a doubt I’m using Wordpress this is my jquery to pick up the link I am clicking and through an anchor ID # it scrolls down to the desired content but need to hide everything and when click appears only the content clicked.

$('.sub-menu a').click(function() {
    var anchor;
    var link = $(this).attr('href');
    if (link.indexOf('#') !== -1) {
        anchor = '#' + link.split('#').pop();
    }

    if (anchor !== undefined) { 
        show().$(anchor) 
        $('html, body').animate({scrollTop: $(anchor).offset().top}, 2000);
    }

});
  • Dude puts at least your HTML there, it’s kind of hard to understand what you want...

  • I made $('. sub-menu a'). click(Function() { var Anchor; var link = $(this). attr('href'); if (link.indexof('#') !== -1) { Anchor = '#' + link.split('#'). pop(); } $('. id-sub'). slideup("slow"); if (Anchor !== Undefined) { $(Anchor). slideDown("slow"); } });

1 answer

1


 $('.sub-menu a').click(function() {
    var anchor;
    var link = $(this).attr('href');
    if (link.indexOf('#') !== -1) {
        anchor = '#' + link.split('#').pop();
    }
    $('.id-sub').slideUp("slow");
     if (anchor !== undefined) {
        $(anchor).slideDown("slow").addClass('#sobre');


     }

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.