Ben
Ben

Reputation: 302

Slide in menu to hide then follow link clicked

I have a menu that slides out from the left. I want it so that when a link in the menu is clicked, the menu slides away and then the link is followed. The code below makes the menu slide away, but for some reason the link is ignored and not followed. How can I change this to also follow the link?

// close menu when links in menu are clicked    
$(document).ready(function () {
    $("#menu-subcat > a").on("click", function(e){
        if($(this).parent().has("ul")) {
            e.preventDefault();
        }
            $("#nav-slider").addClass("closed-slide");
            $("#nav-slider").removeClass("open-slide");
    });
});

Upvotes: 2

Views: 68

Answers (1)

hurrtz
hurrtz

Reputation: 2003

You are telling the link not to trigger its default action with this code:

e.preventDefault();

You can remove this (and the surrounding if-statement) or adjust your code so that the link will be followed once your closing animation is done.

Upvotes: 1

Related Questions