[jQuery] more elegant code...
Hello guys,
is there a way to write this code more elegantly? (I'm sure there
is ;-)
Here is the code (it's working but is not very nice to look at):
setTimeout(show_sentence_1,1000);
setTimeout(show_sentence_2,4000);
setTimeout(show_sentence_3,7000);
function show_sentence_1(){
$("#intro_div .sent_1").show();
setTimeout(hide_sentence,2500);
function hide_sentence(){
$("#intro_div .sent_1").hide();
}
}
function show_sentence_2(){
$("#intro_div .sent_2").show();
setTimeout(hide_sentence,2500);
function hide_sentence(){
$("#intro_div .sent_2").hide();
}
}
function show_sentence_3(){
$("#intro_div .sent_3").show();
setTimeout(hide_sentence,2500);
function hide_sentence(){
$("#intro_div .sent_3").hide();
}
}
I thought to something like this:
setTimeout(show_sentence(1),1000);
setTimeout(show_sentence(2),4000);
setTimeout(show_sentence(3),7000);
function show_sentence(x){
$("#intro_div .sent_" + x + "'").show();
setTimeout(hide_sentence,2500);
function hide_sentence(){
$("#intro_div .sent_" + x + "'").hide();
}
There are a lot of mistakes I know, but I can't make it work!
any suggestion?
Thanks in advance,
Andrea