I'm a jQuery/javascript newbie and I'm having an issue with jQuery which got me stuck for the past few days. It's a script that switches from 3 different divs. It does switch from the first one to the second, but it freezes the script if the random selection tries to switch from the second to the third.
html
<span class="block">
<span class="text1 _shown">1111</span>
<span class="text2 _hidden">2222</span>
<span class="text3 _hidden">3333</span>
</span>
<span class="block">
<span class="text1 _shown">1111</span>
<span class="text2 _hidden">2222</span>
<span class="text3 _hidden">3333</span>
</span>
css
.block{
position:relative;
display:inline-block;
}
._shown{
position:relative;
display:block;
}
._hidden{
visibility: hidden;
}
Javascript
jQuery(function() {
var nbcases = $(".block").length;
var nbvignomg = $(".imgcases").length;
var i;
var chkcases = new Array();
for(var j = 0; j < nbcases-nbvignomg; j++){
chkcases.push(1);
}
function showNextTranscri() {
i = Math.floor(Math.random()*(nbcases-nbvignomg));
$('#texteTransis').html(chkcases);
$('#texteTransis2').html(i);
if(chkcases[i] == 1){
$('.text1').eq(i).fadeOut(700, function() {
$('.text1').eq(i).removeClass("_shown").addClass("_hidden");
$('.text2').eq(i).removeClass("_hidden").addClass("_shown");
chkcases[i] = 2;
$('.text2').eq(i).hide().fadeIn(700).delay(500, showNextTranscri);
});
}
if(chkcases[i] == 2){
$('#texteTransis3').html('[x]');
$('.text2').eq(i).fadeOut(700, function() {
$('.text2').eq(i).removeClass("_shown").addClass("_hidden");
$('.text3').eq(i).removeClass("_hidden").addClass("_shown");
$('.text3').eq(i).fadeIn(700).delay(500, showNextTranscri);
chkcases[i] = 3 ;
});
}
if(chkcases[i] == 3){
$('.text3').eq(i).fadeOut(700, function() {
$('.text3').eq(i).removeClass("_shown").addClass("_hidden");
$('.text1').eq(i).removeClass("_hidden").addClass("_shown");
$('.text1').eq(i).fadeIn(700).delay(500, showNextTranscri);
chkcases[i] = 1;
});
}
}
showNextTranscri();
})();
It seems to be my jQuery line that won't proceed and stucks the entire thing
$('.caseh1#transcri2').eq(i).fadeOut(700, function() {
$('.caseh1#transcri3').eq(i).fadeIn(700).delay(500, showNextQuote);
Thank you very much for any help you can provide.
EDIT: updated with clearer code