Hello,
I have a simple animated menu here that does what it needs to. But I know (in an embarrassing newbie way) the code could be much smarter. I have tried using $(this) and then trying to find the other elements, but I can’t get anything else working. Here’s the snippet of the first few menu items:
// BENEFITS
$("#benefits-button").click(function(){
$("#benefits-button").addClass("active");
$("#features-button").removeClass("active");
$("#advantages-button").removeClass("active");
$("#demos-button").removeClass("active");
$("#clients-button").removeClass("active");
$("#about-button").removeClass("active");
benefits_one();
});
function benefits_one(){
$('#features').stop().animate({left:"-130px"}, 500);
$('#advantages').stop().animate({left:"-130px"}, 500);
$('#demos').stop().animate({left:"-130px"}, 500);
$('#clients').stop().animate({left:"-130px"}, 500);
$('#about').stop().animate({left:"-130px"}, 500, function(){
benefits_two();
})
}
function benefits_two(){
$('#benefits').stop().animate({left:"130px"}, 500);
}
// FEATURES
$("#features-button").click(function(){
$("#features-button").addClass("active");
$("#benefits-button").removeClass("active");
$("#advantages-button").removeClass("active");
$("#demos-button").removeClass("active");
$("#clients-button").removeClass("active");
$("#about-button").removeClass("active");
features_one();
});
function features_one(){
$('#benefits').stop().animate({left:"-130px"}, 500);
$('#advantages').stop().animate({left:"-130px"}, 500);
$('#demos').stop().animate({left:"-130px"}, 500);
$('#clients').stop().animate({left:"-130px"}, 500);
$('#about').stop().animate({left:"-130px"}, 500, function(){
features_two();
})
}
function features_two(){
$('#features').stop().animate({left:"130px"}, 500);
}
// ADVANTAGES
$("#advantages-button").click(function(){
$("#advantages-button").addClass("active");
$("#benefits-button").removeClass("active");
$("#features-button").removeClass("active");
$("#demos-button").removeClass("active");
$("#clients-button").removeClass("active");
$("#about-button").removeClass("active");
advantages_one();
});
function advantages_one(){
$('#benefits').stop().animate({left:"-130px"}, 500);
$('#features').stop().animate({left:"-130px"}, 500);
$('#demos').stop().animate({left:"-130px"}, 500);
$('#clients').stop().animate({left:"-130px"}, 500);
$('#about').stop().animate({left:"-130px"}, 500, function(){
advantages_two();
})
}
function advantages_two(){
$('#advantages').stop().animate({left:"130px"}, 500);
}
and on an on for a few more buttons. Any idea how I could target one element, then target all the rest?