Is there a way to refactor this javascript/jquery?
Posted
by
whyzee
on Stack Overflow
See other posts from Stack Overflow
or by whyzee
Published on 2011-06-22T08:05:00Z
Indexed on
2011/06/22
8:22 UTC
Read the original article
Hit count: 228
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
© Stack Overflow or respective owner