switch (options.effect) {
case 'h-blinds-fadein':
$('.child').each(function(i) {
$(this).stop().css({
opacity: 0
}).delay(100 * i).animate({
'opacity': 1
}, {
duration: options.speed,
complete: (i !== r * c - 1) ||
function() {
$(this).parent().replaceWith(prev);
options.cp.bind('click', {
effect: options.effect
}, options.ch);
}
});
});
break;
case 'h-blinds-fadein-reverse':
$('.child').each(function(i) {
$(this).stop().css({
opacity: 0
}).delay(100 * (r * c - i)).animate({
'opacity': 1
}, {
duration: options.speed,
complete: (i !== 0) ||
function() {
$(this).parent().replaceWith(prev);
options.cp.bind('click', {
effect: options.effect
}, options.ch);
}
});
});
break;
....more cases
}
I have alot of similiar other cases. One way i could think of is to write functions ? i’m not sure i’m still fairly new to the language
im sorry, i is the index of the each() function which is the size of $(‘.child’), and r and c are just the ‘rows’ and ‘columns’ of the grid which contains ‘.child’.
r and c can be any number, e.g. r=5 c=5
Rather then using a switch, store the case specific data in a hash.
Then run the main block of code and extract anything effect type specific from the hash.