I have a list of functions:
function randomiseiconscycle1() {
$("#iconTwoContainer img, #iconFiveContainer img, #iconSevenContainer img").fadeIn(300);
setTimeout( function(){
$("#iconTwoContainer img, #iconFiveContainer img, #iconSevenContainer img").fadeOut(300);
},200);
function randomiseiconscycle2() {
$("#iconOneContainer img, #iconSixContainer img").fadeIn(300);
setTimeout( function(){
$("#iconOneContainer img, #iconSixContainer img").fadeOut(300);
},200);
}
everytime i click this button i have i want to activate one of the 8 functions (like above) randomly.
any help would be much appreicated.
Put references to the functions in an array:
var iconcycle = [
randomiseiconscycle1, randomiseiconscycle2,
randomiseiconscycle3, randomiseiconscycle4,
randomiseiconscycle5, randomiseiconscycle6,
randomiseiconscycle7, randomiseiconscycle8
];
Now you can pick one at random and call it:
iconcycle[Math.floor(Math.random() * iconcycle.length)]();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With