How to optimize my jquery code
I'm working on a new design for an organization at my college, and I've
used JQuery to get my nav bar to do what I want it to do (slide down on
specific nav-item click, slide back up if that or another nav-item is
clicked [and slide the new nav-item down if the second case is true]).
Relevant JQuery:
function toggleMembers() {
if ($("#members-drop-down").is(":visible")) {
$("#members-container").animate(
{
opacity: "0"
},
600,
function(){
$("#members-drop-down").slideUp();
}
);
$("#members").removeClass('active');
}
else if ($("#about-drop-down").is(":visible")) {
$("#about-container").animate(
{
opacity: "0"
},
600,
function(){
$("#about-drop-down").slideUp();
}
);
$("#about").removeClass('active');
$("#members-drop-down").slideDown(600, function(){
$("#members-container").animate(
{
opacity: "1"
},
600
);
});
$("#members").addClass('active');
}
else if ($("#store-drop-down").is(":visible")) {
$("#store-container").animate(
{
opacity: "0"
},
600,
function(){
$("#store-drop-down").slideUp();
}
);
$("#store").removeClass('active');
$("#members-drop-down").slideDown(600, function(){
$("#members-container").animate(
{
opacity: "1"
},
600
);
});
$("#members").addClass('active');
}
else {
$("#members-drop-down").slideDown(600, function(){
$("#members-container").animate(
{
opacity: "1"
},
600
);
});
$("#members").addClass('active');
}
}
Unfortunately, though, the JQuery I wrote takes up more space than all of
the HTML. How can I shorten and optimize this?
My JSFiddle with the full code.
No comments:
Post a Comment