Tell me, please, how to make the random block instead of the first block .eq(0)
selected in your script instead of the first block, and then everything went in order?
$(document).ready(function() { $('.text .text-block').eq(0).addClass("active").fadeIn(1000); // Показываем первый блок, можно и не первый, если прописать нужную цифру в eq() setInterval('blockAnimate();', 5000); // Вызываем функцию для смены блока каждые 5 секунд }); // Функция для смены блоков, показывает блоки по очереди, начальный блок задаётся выше function blockAnimate() { var length = $('.text .text-block').length - 1; $('.text .text-block').each(function(index) { if($(this).hasClass('active') && index != length) { $(this).removeClass("active").fadeOut(1000).next('.text-block').addClass("active").delay(1000).fadeIn(1000); return false; } else if (index == length) { $(this).removeClass('active').fadeOut(1000); $('.text .text-block').eq(0).addClass("active").delay(1000).fadeIn(1000); return false; } }); };
0
with the number obtained by chance, for example usingMath.random
- Grundy