on the site under wordpress, given the change of quotes in the following way:
In the central page there is a code:

<div class="t-quote animated fadeInUp"> <?php the_field('default_quote'); ?> </div> <div class="hide quote-block"> <?php if ( have_rows('quote') ): while ( have_rows('quote') ) : the_row(); ?> <div class="quote-text"><?php the_sub_field('quote_text'); ?></div> <?php endwhile; endif; ?> </div> 

There is also javascript:

  $('.slider-bg ul').carouFredSel({ items: 1, pagination: { container: '.pager', anchorBuilder: function(nr) { return "<a href='#' class='pag'><i class='fa fa-circle' aria-hidden='true'></i></a>"; } }, responsive: true, auto: { timeoutDuration: 5000 }, scroll: { items: 1, fx: "crossfade", duration: 1000, pauseOnHover: false, onAfter: function(t) { var quote = quotes[Math.floor(Math.random() * quotes.length)]; $('.t-quote').html("<div class='animated fadeInUp'>" + quote + "</div>"); } } }); 

I advise you to substitute the current index of the array being processed, something simple and elegant, like in PHP: instead of var quote = quotes[ рандомное число] , like in PHP: getRowIndex() , so that the quotes will pop up not by chance, but consistently. I'm not a programmer, but I want to figure it out.

  • Java SE where? - ilyaplot
  • 3
    Tasks on fl.ru, and here are the questions. Show what you did. - ilyaplot
  • Dear, this task was developed on fl, ru. my code is not here, but I need to fix it, will you help? - LAndrey
  • 3
    @LAndrey contact the one who did this to you on fl.ru? ;) - D-side
  • Am I having no right to figure out the code myself? Yes, I have, consider, the 0th level of programming, compared to you, Gurus, who have the right to judge, But where in the rules is the qualification of the input level to ask questions? - LAndrey

1 answer 1

 var currentQuote = 0; // Индекс текущей цитаты. Начало - 0 $('.slider-bg ul').carouFredSel({ items: 1, pagination: { container: '.pager', anchorBuilder: function(nr) { return "<a href='#' class='pag'><i class='fa fa-circle' aria-hidden='true'></i></a>"; } }, responsive: true, auto: { timeoutDuration: 5000 }, scroll: { items: 1, fx: "crossfade", duration: 1000, pauseOnHover: false, onAfter: function(t) { var quote = quotes[currentQuote]; // Если текущая цитата последняя, сбрасываем индекс в начало, иначе прибавляем 1 currentQuote = (currentQuote == quotes.length - 1) ? 0 : currentQuote+1; последняя, $('.t-quote').html("<div class='animated fadeInUp'>" + quote + "</div>"); } } }); 

  • Thank you so much, gracefully and it works! I myself would have suffered for a long time. I did not understand what the ball was reduced to me, because "the most stupid question is unspecified." But still, as I read, there is no such method for taking an instant "snapshot" of the current array index (or how someone here cyberforum.ru/ javascript / thread867223.html wrote "array cursor")? - only through sorting methods, like arr.forEach () or arr.indexof () or through a cycle like yours. - LAndrey
  • Initially, the question looked like a problem. And then lovers of free to get the code is complete. then, apparently, corrected the question and it turned out to answer. The enumeration functions were not needed here, because onAfter each iteration is performed. It was just necessary to specify the desired item at the time of the slide change. - ilyaplot