Looking for a better way to make a FAQ page with fading objects
Hi all
I'm kind of stuck here. I wanted to build a FAQ page with about 20 questions. To show the content of the questions I have a list with all questions and when you click on one question the answer is showing. Now I use the animation function (opacity:toggle) and a if/else to check which answer to fade in or out. I also use variables to know the status of the layer.
But since I have about 20 layers the JS will be huge and repeats itself. And if content is added I would have to change all code.
Is there a better way to do that, maybe more dynamic?
here's my script so fare:
- var que1 = 'on';
- var que2 = 'off';
- var que3 = 'off';
- …
- $("a.q1").click(function() {
- if (que1 == 'off' && que2 == 'on') {
- $("#que2").animate({
- opacity: 'toggle'
- }, setTimeout, function() {
- $("#que1").animate({
- opacity: 'toggle'}, 500);
- });
- que1 = 'on';
- que2 = 'off';
- } else if (que1 == 'on') {
-
- } else if (que1 == 'off' && que3 == 'on') {
- $("#que3").animate({
- opacity: 'toggle'
- }, setTimeout, function() {
- $("#que1").animate({
- opacity: 'toggle'}, 500);
- });
- que1 = 'on';
- que3 = 'off';
- } else if …